1
00:00:00,270 --> 00:00:09,660
In this video, we are going to see how a lambda invoke asynchronously using commands so we can see

2
00:00:09,660 --> 00:00:14,310
the image on the slide that shows client invoking a lambda function asynchronously.

3
00:00:14,490 --> 00:00:18,450
Edible is lambda cues the events before sending them to the function.

4
00:00:18,780 --> 00:00:25,620
For asynchronous invocation, Lambda plays the event in a queue and returns a success response without

5
00:00:25,620 --> 00:00:27,090
additional information.

6
00:00:27,630 --> 00:00:34,410
A separate process reads the events from the queue and sent them to our lambda function in order to

7
00:00:34,410 --> 00:00:36,570
invoke a function asynchronously.

8
00:00:36,600 --> 00:00:40,200
We should set the invocation type parameter to the event.

9
00:00:41,620 --> 00:00:44,110
You can see the image on the slide.

10
00:00:44,140 --> 00:00:50,230
Here is an example in location, a invocation to a lambda click command.

11
00:00:50,410 --> 00:00:53,740
You can see that the invocation type is event.

12
00:00:55,110 --> 00:01:00,450
So here you can find the location type event and there's a response says code 202.

13
00:01:00,930 --> 00:01:06,630
So the output file, which is the response, JSON doesn't contain any information, but still it is

14
00:01:06,630 --> 00:01:08,760
created when you run this command.

15
00:01:08,880 --> 00:01:14,820
If Lambda isn't able to add the event to the queue, the error message appears in the command output

16
00:01:15,240 --> 00:01:21,840
a lambda minutes, the function asynchronous event queue and attempts to retry on errors if the function

17
00:01:21,840 --> 00:01:28,110
returns an error a dubious lambda attempts to run it two more times with one minute wait between the

18
00:01:28,110 --> 00:01:32,880
first two attempts and 2 minutes between the second and the third attempts.

19
00:01:33,390 --> 00:01:38,420
Function errors include error returned by the function code and the error is returned by the functions

20
00:01:38,430 --> 00:01:40,710
runtime such as timeout and so on.

21
00:01:42,150 --> 00:01:49,410
So during the course so far we only invoke our lambda functions with synchronously using the Sing Invocation

22
00:01:49,410 --> 00:01:50,040
Command.

23
00:01:50,070 --> 00:01:57,630
Now let's try to invoke Lambda Functions asynchronously with providing the invocation type as an event

24
00:01:58,140 --> 00:01:58,930
for that purpose.

25
00:01:58,950 --> 00:02:03,570
Please open the Visual Studio code and create an EVE lecture folder.

26
00:02:03,780 --> 00:02:09,960
And as you remember that in the last video we have created the calculator lambda function and this is

27
00:02:09,960 --> 00:02:15,720
the or imagine object I have created in my case object as we described in the last video.

28
00:02:15,750 --> 00:02:22,730
Now I am going to invoke this function again, synchronously and asynchronously with two types.

29
00:02:22,740 --> 00:02:28,980
So if you come back to command text, if you scroll down, let's sync invocation.

30
00:02:29,160 --> 00:02:37,230
This function, if you copy this line of code and paste in here, let me create.

31
00:02:39,240 --> 00:02:40,160
And paste again.

32
00:02:40,950 --> 00:02:47,850
So we will invoke our collocated function with giving the payload event, JSON, and we don't specify

33
00:02:47,850 --> 00:02:51,240
any information about the invocation site.

34
00:02:51,270 --> 00:02:56,740
So that means this will be invoke or function synchronously and this will be create response station

35
00:02:56,760 --> 00:03:03,810
including the response calculated value of the function hit enter and see what's happened.

36
00:03:03,900 --> 00:03:09,450
So this will be returned such 200 and generate the response JSON file.

37
00:03:09,480 --> 00:03:13,860
And if you open the JSON file, you can see the response of the function.

38
00:03:13,860 --> 00:03:20,400
So this is the synchronous invocation that returns the value of the function response from the this

39
00:03:20,430 --> 00:03:21,660
event JSON object.

40
00:03:21,690 --> 00:03:28,260
Okay, so we have all these know how we can invoke synchronously, but this time let me focus on the

41
00:03:28,260 --> 00:03:29,490
asynchronous invocation.

42
00:03:29,490 --> 00:03:36,750
So if you open the command text file and scroll down, we have also invoked this lambda function asynchronously

43
00:03:36,780 --> 00:03:37,800
for that purpose.

44
00:03:37,800 --> 00:03:45,000
We have only include this property which is the invocation type event to invoke these function asynchronously.

45
00:03:45,030 --> 00:03:48,330
Please copy this line of code and come here.

46
00:03:48,420 --> 00:03:56,580
And before proceeding these command in our command line, I would like to remove this response JSON

47
00:03:56,580 --> 00:03:57,090
file.

48
00:03:57,120 --> 00:04:01,680
Okay, now paste this select command and hit enter.

49
00:04:01,950 --> 00:04:05,610
Make sure that your invocation type should be event this time.

50
00:04:05,610 --> 00:04:08,760
As you can see, that is called return 202.

51
00:04:08,760 --> 00:04:15,810
And if you check the response JSON file, you don't see any response because we are invoking this lambda

52
00:04:15,810 --> 00:04:17,340
function asynchronously.

53
00:04:17,340 --> 00:04:19,410
See response object is null.

54
00:04:19,710 --> 00:04:25,080
As you can see that the output file which is the response JSON doesn't contain any information but still

55
00:04:25,080 --> 00:04:28,020
created when we run and invoke this command.

56
00:04:28,050 --> 00:04:32,910
If Lambda isn't able to add event to the queue, the error message appear in the command output in the

57
00:04:32,910 --> 00:04:33,870
response json.

58
00:04:34,080 --> 00:04:40,050
So let's verify from the OR invocations from the message console.

59
00:04:40,080 --> 00:04:43,800
Please go to monitor and view cloud logs for the calculator project.

60
00:04:44,430 --> 00:04:51,030
And if you open the latest log stream, you can see the incoming events is the same and we are returning.

61
00:04:51,030 --> 00:04:53,910
The result is ten for synchronous invocation.

62
00:04:54,090 --> 00:05:02,910
And if you scroll down and see again we are invoking this function as the same input event object,

63
00:05:02,910 --> 00:05:10,710
but this time we don't have return any result into the object because this is executed asynchronously.

64
00:05:10,740 --> 00:05:18,510
We don't see this result into the response JSON file, but we can see the result log into the our cloud

65
00:05:18,510 --> 00:05:19,320
watch logs.

66
00:05:19,830 --> 00:05:25,920
As you can see that we have successfully invoke our lambda function synchronous and asynchronous way

67
00:05:25,920 --> 00:05:34,050
using the ACL commands before proceeding to course, we should not forget to remove and clear a resources

68
00:05:34,050 --> 00:05:35,070
for that purpose.

69
00:05:35,070 --> 00:05:40,650
Please clean up your resources what we have created in this lecture and section.

70
00:05:40,650 --> 00:05:45,120
For that purpose, I'm going to go to the Lambda functions.

71
00:05:45,950 --> 00:05:52,790
And we have only one calculator project select these calculator project actions, delete and write.

72
00:05:53,550 --> 00:05:56,730
Delete message and click the delete button.

73
00:05:56,760 --> 00:06:02,460
This will be delayed our lambda functions and we don't create any other resource during this section.

74
00:06:02,460 --> 00:06:05,160
So now we can proceed the next section.
