In this video, we are going to see how a lambda invoke asynchronously using commands so we can see
the image on the slide that shows client invoking a lambda function asynchronously.
Edible is lambda cues the events before sending them to the function.
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 sent them to our lambda function in order to
invoke a function asynchronously.
We should set the invocation type parameter to the event.
You can see the image on the slide.
Here is an example in location, a invocation to a lambda click command.
You can see that the invocation type is event.
So here you can find the location type event and there's a response says code 202.
So the output file, which is the response, JSON doesn't contain any information, but still it is
created when you run this command.
If Lambda isn't able to add the event to the queue, the error message appears in the command output
a lambda minutes, the function asynchronous event queue and attempts to retry on errors if the function
returns an error a dubious lambda attempts to run it two more times with one minute wait between the
first two attempts and 2 minutes between the second and the third attempts.
Function errors include error returned by the function code and the error is returned by the functions
runtime such as timeout and so on.
So during the course so far we only invoke our lambda functions with synchronously using the Sing Invocation
Command.
Now let's try to invoke Lambda Functions asynchronously with providing the invocation type as an event
for that purpose.
Please open the Visual Studio code and create an EVE lecture folder.
And as you remember that in the last video we have created the calculator lambda function and this is
the or imagine object I have created in my case object as we described in the last video.
Now I am going to invoke this function again, synchronously and asynchronously with two types.
So if you come back to command text, if you scroll down, let's sync invocation.
This function, if you copy this line of code and paste in here, let me create.
And paste again.
So we will invoke our collocated function with giving the payload event, JSON, and we don't specify
any information about the invocation site.
So that means this will be invoke or function synchronously and this will be create response station
including the response calculated value of the function hit enter and see what's happened.
So this will be returned such 200 and generate the response JSON file.
And if you open the JSON file, you can see the response of the function.
So this is the synchronous invocation that returns the value of the function response from the this
event JSON object.
Okay, so we have all these know how we can invoke synchronously, but this time let me focus on the
asynchronous invocation.
So if you open the command text file and scroll down, we have also invoked this lambda function asynchronously
for that purpose.
We have only include this property which is the invocation type event to invoke these function asynchronously.
Please copy this line of code and come here.
And before proceeding these command in our command line, I would like to remove this response JSON
file.
Okay, now paste this select command and hit enter.
Make sure that your invocation type should be event this time.
As you can see, that is called return 202.
And if you check the response JSON file, you don't see any response because we are invoking this lambda
function asynchronously.
See response object is null.
As you can see that the output file which is the response JSON doesn't contain any information but still
created when we run and invoke this command.
If Lambda isn't able to add event to the queue, the error message appear in the command output in the
response json.
So let's verify from the OR invocations from the message console.
Please go to monitor and view cloud logs for the calculator project.
And if you open the latest log stream, you can see the incoming events is the same and we are returning.
The result is ten for synchronous invocation.
And if you scroll down and see again we are invoking this function as the same input event object,
but this time we don't have return any result into the object because this is executed asynchronously.
We don't see this result into the response JSON file, but we can see the result log into the our cloud
watch logs.
As you can see that we have successfully invoke our lambda function synchronous and asynchronous way
using the ACL commands before proceeding to course, we should not forget to remove and clear a resources
for that purpose.
Please clean up your resources what we have created in this lecture and section.
For that purpose, I'm going to go to the Lambda functions.
And we have only one calculator project select these calculator project actions, delete and write.
Delete message and click the delete button.
This will be delayed our lambda functions and we don't create any other resource during this section.
So now we can proceed the next section.