In this video, we are going to see how to recruit our lambda functions.
That means you will see a Lambda Invocation types.
So this lambda function is using a river for various use cases.
Sometimes we want to invoke lambda function over HTTP and other times trigger a function based on different
events.
It is extremely useful to understand the different ways that we can invoke lambda function.
Here are three different ways we can invoke lambda functions.
You can see in here a double is Lambda has three invocation types.
Lambda Synchronous Invocation.
Lambda Asynchronous Invocation.
Lambda Event Source Mapping with Pulling Invocation.
So you can all see in location types in one image.
Synchronous invocation is triggered by push model and execute immediately and wait response.
We can say request response model.
Asynchronous invocation is triggered by event model and executes.
Asynchronous.
Don't wait.
Immediate response.
Event source mapping invocation is triggered by pol based.
That means lambda function receive multiple items.
So let's see one by one and explain these types.
Lambda Synchronous invocation.
This is one of the simple Lambda Invocation model in this communication type.
Lambda functions execute immediately when you perform the Lambda Invoke by API call.
So when we perform a Lambda Invoke an API call, we wait for the function to process the function and
return back to the response.
The response data includes the function response and additional data which can be retrieved from the
Dynamo DB or some other resources.
But the idea is we should wait.
A response from the synchronous invocation.
A common scenario for synchronous invocation is the API gateway, Lambda and Dynamo DB integration.
You can see in the Image API, Gateway, Lambda and Dynamo DB that we can perform CRUD operation for
a particular Dynamo DB table with exposing APIs from the API gateway.
The important thing is in here, the invocation type flag should be request response.
This instructs a place to execute our lambda function and wait for the response of function to complete.
When we perform the synchronous invocation, we are responsible for inspecting the response and determining
if there was an error lifetime of execution and decide to retry invocation.
We can perform synchronous requests most in location using a double CLI SDK and many other options.
You can see an example of synchronous invocation using a double click.
See that we are running the lambda invoke comments on CLI.
As you can see that when we specify the invocation type LIC is request response, that means it will
execute our function and wait for the function response in order to complete and return response.
The important part is we are responsible for checking the request, checking the response and determining
whether it is an error or we should try the invoke.
So in this synchronous invocation, we are waiting response and according to this response, we are
checking the response data and it is looking for it is getting error or not.
If it is getting error, we are going to retry the invoke again.
There are many services that can trigger lambda function synchronously here.
Some of them in here.
You can see that application load will answer Amazon Incognito, Amazon, lakes, Alexa API, Gateway
Cloud, Front Kinesis Data streams and so on.
So now the second invocation type is Lambda Asynchronous invocation.
In this communication type, Lambda function works with the events and invoke by events and not respond
immediately.
Basically, we can invoke a lot of function asynchronously.
After that, Lambda sends the event an internal queue and returns a success response without any additional
information.
After that, a separate process reads the events from the queue and runs our lambda function.
So you can see a common scenario for asynchronous invocation is the S3 Lambda and Dynamo.
DB You can see in the Image HD or Amazon sense a sense trigger an event and this will be triggered the
lambda asynchronously and it will extend to interact with the dynamo.
DB In the diagram, Amazon S3 will call the Lambda Asynchronous when a new object is written into the
bucket.
Amazon S3 has several events that can trigger to a lambda.
For example, we can set that a new object is uploading to the bucket.
We can trigger an event today lambda that is execute lambda function asynchronously.
In order to invoke a function asynchronously, we should set the invocation type parameter to event.
So it is very important you can see an example of the asynchronous invokes using the SLA.
We can see that we are running a double lambda invoke comment and the invocation type is event one.
We specify the invocation type parameter value as event.
If the function failed, the bullets will automatically retry the invoke device because in asynchronous
communication the lambda is automatically triggered by the triggered invoke by twice when there is an
error by default.
A double is lambda sets a retry policy for asynchronous invocations.
Your function will be invoked twice if there is an error in order to avoid event losses.
When using asynchronous lambda, always attach a dead letter Q on the function in order to save events
that weren't successfully processed.
Here you can list of the services that invoke Lambda function asynchronously as you set that Amazon
S3, Evan SAS is cloud formation, cloud watch logs and events called cosmic pull based invokes and
so on.
So if you come to the last location type, which is the event source mapping with polling location,
this is the poll based location model allows us to integrate with the bullets, streams and queue based
services.
These services don't invoke a lambda function directly.
Lambda will pull from the ASCs or kinesis streams, retrieve records and invoke the functions.
A.W. Islam the event source mapping manage the polar and performs the synchronous inverse of our function.
Data streams or cues are read in the batch.
The function receives multiple items when executing to function, so a batch size can configure according
to the service type.
And after that, the event source mapping will send data according to batch size.
If the batch size is too large to send in one event, it has to be split up, resulting in events with
smaller number of items than the batch size.
So you can see in the image a common scenario for event source mapping with polling location is the
squares and a place lambda you can see in the image almost on squares and lambda using the event source
mapping basically lambda function pulling events from the a base case.
Let me explain more clearly in this diagram.
Amazon has some key records.
These records can be added from other services like event, SMS and so on.
So the idea is that we have some queue message in the Amazon queue.
After that, a lambda function, pull the events from the Amazon case and receive Q records with event
source mapping invocation.
So lambda function retrieve queue records according to the batch size property of polling configuration.
Another common scenario for my source mapping with polling location is stream based processing.
These are the Kinesis and Dynamo DB streams that can lambda pull the stream records with one source
mapping in locations.
So the base size property is very important.
We give the example of the x and lambda and we said that the stream based processing dynamo DB streams
and kindnesses streams using the event based event source mapping location.
And here is the list of the services that invoke Lambda functions as an event source mapping.
These are the Amazon Kinesis, Amazon Dynamo, DB, and Amazon simple queue services.
As you can see that we have seen several ADA Lambda Invocation types.