In this section, we are going to do a hands on lab, which is the invoke lambda function asynchronously
using Amazon S3 to trigger the Lambda function.
So before we start, let me explain one important topic, which is the Lambda asynchronous invocation.
So several ADA services, for example, Amazon S3 and Amazon SAS invoke functions asynchronously to
process the events.
So basically when we invoke a function asynchronously, we don't wait for a response from the function
code.
So how Lambda handles asynchronous invocation?
You can see the image on the slide.
Basically client invoke the lambda function asynchronously.
Lambda queue the events before sending them the function.
You can see that client invoke lambda function asynchronously, but Lambda has internal event queue
that stored the events in here and execute after that asynchronously.
So for asynchronous invocation, Lambda plays the event in a queue and returns a success response without
additional information.
A separate process reads the events from the queue and send them into function.
So in order to invoke a function asynchronously, we should set the invocation type parameter to the
event so you can see the example command, which is the cli command.
Invoke lambda function asynchronously.
You can see in here a w is lambda invoke and we provide the function name.
The important part is here, which is the invocation type is event.
That means we invoke these lambda function asynchronously and also the output file could be the response
JSON, but the output file is one station doesn't contain any information, but it is still created
when we run this command.
If Lambda isn't able to add the event to the queue, the error message appear in the command output.
So you can remember the calculated example at the beginning of the Lambda ClA examples.
We create lambda function, put a calculator code and invoke calculated lambda function synchronously
and asynchronously.
So if you summarize how lambda works with the asynchronously, basically Lambda manage the function
asynchronous event queue and attempts to retry on the errors.
If the function returns an error, Lambda attempts to run it two more times with the one minute wait
between the first two attempts and 2 minutes between the second and third attempts.
Function errors include the error returned by the function code and the error returned by the function
runtime such as the timeout.
So that means lambda is a internal retry mechanism.
If there is an exception in the lambda function code, it is retried two times and after that it return
back to asynchronous error to the client application.