In this video, we are going to see how to recruit our lambda functions.
That means you will see a Lambda Invocation types.
After that, we will map these Lambda Invocation types with our course one developing serverless e-commerce
application.
So this Lambda Invocation types will be our serverless journey when developing our service ecommerce
application.
So Islam, the 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 place 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 or function to complete.
When we perform the synchronous invocation, we are responsible for inspecting the response and determining
if there was an error like time or 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 c that we are running the lambda invoke
comments on cli.
As you can see that when we specify the invocation type like 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 lambda 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 dynamic DB.
You can see in the Image S3 or Amazon sense a sense trigger an event and this will be triggered a number
asynchronously and a double is lambda interact with the dynamo db in the diagram Amazon S3 will call
the Lambda asynchronously 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 the into bucket.
We can trigger an event today lambda that is executed 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.
When we specify the invocation type, parameter value is event.
If the function failed a the 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 event.
SNS S is cloud formation, cloud watch looks and Events Code Command, 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 police streams and queue based
services.
These services don't invoke a lambda function directly.
Lambda will pull from the available case 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
case and a lambda you can see in the image Amazon case and lambda using the event source mapping, basically
lambda function pulling events from the case.
Let me explain more clearly in this diagram.
Amazon case 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 Q 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 Q records according to the batch size property of polling configuration.
Another common scenario for one source mapping with polling location is string based processing.
These are the Kinesis and Dynamo DC streams that can learn the pole the stream records with event 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 by A.B. streams
and kindness 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 Q Services.
As you can see that we have seen several a number in location types.