1
00:00:00,300 --> 00:00:06,600
In this section, we are going to do a hands on lab, which is the invoke lambda function asynchronously

2
00:00:06,630 --> 00:00:09,810
using Amazon S3 to trigger the Lambda function.

3
00:00:10,320 --> 00:00:17,280
So before we start, let me explain one important topic, which is the Lambda asynchronous invocation.

4
00:00:17,940 --> 00:00:26,640
So several ADA services, for example, Amazon S3 and Amazon SAS invoke functions asynchronously to

5
00:00:26,640 --> 00:00:27,840
process the events.

6
00:00:28,320 --> 00:00:33,780
So basically when we invoke a function asynchronously, we don't wait for a response from the function

7
00:00:33,780 --> 00:00:34,260
code.

8
00:00:34,770 --> 00:00:37,770
So how Lambda handles asynchronous invocation?

9
00:00:37,950 --> 00:00:40,080
You can see the image on the slide.

10
00:00:40,080 --> 00:00:43,560
Basically client invoke the lambda function asynchronously.

11
00:00:43,590 --> 00:00:47,490
Lambda queue the events before sending them the function.

12
00:00:48,310 --> 00:00:55,030
You can see that client invoke lambda function asynchronously, but Lambda has internal event queue

13
00:00:55,030 --> 00:00:59,200
that stored the events in here and execute after that asynchronously.

14
00:01:00,050 --> 00:01:06,440
So for asynchronous invocation, Lambda plays the event in a queue and returns a success response without

15
00:01:06,440 --> 00:01:07,820
additional information.

16
00:01:08,360 --> 00:01:13,250
A separate process reads the events from the queue and send them into function.

17
00:01:13,370 --> 00:01:18,980
So in order to invoke a function asynchronously, we should set the invocation type parameter to the

18
00:01:18,980 --> 00:01:24,210
event so you can see the example command, which is the cli command.

19
00:01:24,230 --> 00:01:26,300
Invoke lambda function asynchronously.

20
00:01:26,330 --> 00:01:31,070
You can see in here a w is lambda invoke and we provide the function name.

21
00:01:31,100 --> 00:01:34,600
The important part is here, which is the invocation type is event.

22
00:01:34,610 --> 00:01:41,000
That means we invoke these lambda function asynchronously and also the output file could be the response

23
00:01:41,000 --> 00:01:47,480
JSON, but the output file is one station doesn't contain any information, but it is still created

24
00:01:47,480 --> 00:01:48,980
when we run this command.

25
00:01:49,010 --> 00:01:55,280
If Lambda isn't able to add the event to the queue, the error message appear in the command output.

26
00:01:55,760 --> 00:02:00,280
So you can remember the calculated example at the beginning of the Lambda ClA examples.

27
00:02:00,290 --> 00:02:06,560
We create lambda function, put a calculator code and invoke calculated lambda function synchronously

28
00:02:06,560 --> 00:02:07,920
and asynchronously.

29
00:02:07,940 --> 00:02:14,240
So if you summarize how lambda works with the asynchronously, basically Lambda manage the function

30
00:02:14,240 --> 00:02:17,440
asynchronous event queue and attempts to retry on the errors.

31
00:02:17,450 --> 00:02:23,510
If the function returns an error, Lambda attempts to run it two more times with the one minute wait

32
00:02:23,510 --> 00:02:28,280
between the first two attempts and 2 minutes between the second and third attempts.

33
00:02:28,610 --> 00:02:33,530
Function errors include the error returned by the function code and the error returned by the function

34
00:02:33,530 --> 00:02:35,440
runtime such as the timeout.

35
00:02:35,450 --> 00:02:38,960
So that means lambda is a internal retry mechanism.

36
00:02:38,960 --> 00:02:44,210
If there is an exception in the lambda function code, it is retried two times and after that it return

37
00:02:44,210 --> 00:02:47,690
back to asynchronous error to the client application.
