In this video, we are going to do hands on OP which is the ADA Lambda destinations to excuse the data
queue case so you can see the image on the slide.
We will follow the previous hand on loop, but I will choose to create a new lambda function and set
a destination to Amazon X and we will throw an exception in this lambda function and see how this invocation
redirect to Amazon s case is a payload case.
So here you can see the steps that we are going to do one by one.
The first step is throwing an error in Lambda invocations and the second step is retry asynchronous
invocations.
This will be happen from the lambda automatically and the last step is the send destination to the Amazon
case queue records.
So we will follow these steps and perform destination case in the Lambda function.
To do so, please open the Amazon console and go to Lambda functions and we are going to create a native
lambda function.
So click the create function and say that async destination.
Function and I'm going to leave as it is for all configurations and click to create function.
This will be create a new execution role for our newly created these async destination function.
So I will explain how we can add required permission to this lambda function execution role.
Okay.
Our new function is created successfully and if you come the configuration and see the permissions,
new role is created for our lambda functions.
Okay.
If you come to the our code section and if you scroll down, the first thing I should do that I'm going
to throw an exception.
So that means please add this to any error line of code.
We will throwing an exception in this function and I'm going to deploy this function.
So that means this will be returned exception for all invocations because we will test how these lambda
function works in a on failure scenario.
We're setting up the destination.
Okay.
After adding this throw exception line of code, we can test this function with the console.
If you click the test and create any test event name and you can set a Helloworld event JSON object.
And if you go on top of this page, we can save this template and click the test button in order to
invoke our lambda function.
As you can see that the response come in here, we basically return back to error, which is the lambda
error message.
And that means when we invoke our lambda function, it is return also exception.
So when we invoke from a management console, this will invoke request response.
So that means we invoke synchronously.
So that means when we click this test button, this will be run the invoke synchronously in our lambda
function.
But this section we will focus on asynchronous invocation in order to use destinations.
So for that purpose we can go to configuration.
And if you come here and see that, that should be an asynchronous invocation section.
If you click the asynchronous invocation, we can see that we have some configurations that is the maximum
age of event, retry attempts and data services.
If you click the edit button, you can see and change these restrictions and the editor cues.
When this function is asynchronous trigger, see that we can set the retry attempts.
This is the maximum number of times to retry when the function returns an error.
So since our function is returning an error now, this asynchronous invocation should be retried to
attempts, the invocation of the lambda function.
And we can also set the letter Q from the Sans and S case.
So now I am not going to change anything.
I'm going to go back to our lambda function and see the main page of the lambda function.
You can remember that we added the trigger for invocations from the different services.
We added Trigger to API Gateway and also Amazon S3.
And now I'm going to focus on the destination part.
So that means we will designate the invocation to other services after the own success or on failure
issues.
So if you click the add destinations, you can see the configurations.
The first configuration is the source.
This is the type of the invocation that maps to the destination.
We should check the asynchronous invocation and we can also set the three location.
But in our case we will focus on the asynchronous invocations.
And here the second configuration is the condition.
The condition for the own failure or the on on success we can both set and configure on failure and
on success executions for the lambda function set to failure.
And here you can see the destination type, which is the destination services when the invocation happens
on failure or on success, for example, on failure case, we can set the topic case to another lambda
function and event with each event pass.
So we will select the case and we should provide the same.
We can see the destination.
We don't have any.
Q So that's why we can configure our destination.
Now, in order to do that, please go to Amazon case and open a new A management console, Amazon case
page and click the create queue.
I'm going to click.
Create a queue for our definition.
You can see the we are type selecting the type as a standard and the name of this queue should be lambda
queue and I'm not going to change any configuration, so leave as it is and go at the end of the page
and click the create queue.
This will be the our destination queue for lambda function.
So Lambda queue is created successfully.
If you come back to our lambda function, so I'm going to go back to functions and create and open the
page from the beginning.
So now if you click the add destinations, we can configure the destination for lambda function, select
the asynchronous invocation, select on payload and destination type should be the case queue.
Now we have created the lambda queue, so that's why I can set the lambda queue for the destination
of this lambda function.
And after that you can see that there is a warning.
Come here.
Our function execution rule doesn't have permission to send result to destination, so our lambda function
doesn't have permission to add item into queue action.
So by clicking the save button they are going to ADA, which is going to attempt to add permission for
the role.
So if you click the save button, this will be required permission into our lambda execution role.
This is a very good feature from the ADA.
Yes.
We don't need to add the required permission to do our execution roll.
Yes.
As you can see that the illustrations of that are asynchronous invocation.
Our lambda function will be designated to Amazon X and you can see the configurations and destination.
This destination is for the asynchronous invocation and the condition is on failure and the status service
is lambda queue.
Okay.
If you go to our permissions, if you go to permissions, you should require to refresh the page to
see the latest edit permission.
So go to refresh the page and go to permissions and go to resource summary.
If you expand this, you can see the Amazon case is added successfully, which is the allowing send
message these permissions edit from the edit place when we are configured our destination as Amazon
asks.
Okay, very good.
Now it is time to test our destination PID.
We should invoke lambda function asynchronously, so that's why we can't run our test section in the
mission console.
That means we will run a command in order to invoke this function asynchronously.
For that purpose, please open the studio code.
I have created a separate lecture folder and the command text file.
So in the command text file we are going to async invocation to our lambda function we're using to select
commands.
You can see the structure we are using, the lambda invoke command, placing the function name and this
is the important which is the invocation type should be event in order to invoke the lambda function
asynchronously and we can give additional configurations.
So I have prepared a minimum cell command that we will invoke our lambda function asynchronously.
I'm placing the function name, you can copy paste from the function name from the mission console and
give the invocation type as an event and response back to response JSON file.
So for that purpose, I'm going to copy this command and go to a required section folder.
You can go to section folder and after the lecture folder.
Now in here, I'm going to run this command in order to invoke our lambda function asynchronous.
Hit enter and see what happens.
So see that we got the status quo.
202 So that means the lambda asynchronous execution happens successfully.
It doesn't return any response.
You can check the response JSON file.
We don't get any response.
We should check the status from the console logs.
But the idea is that when you see the code as a two under two, that means the asynchronous invocation
execute successfully.
For that purpose, please go to a management console, go to monitor and V cloud watch logs.
So review cloud which looks to see execution logs.
So if you if you come to log stream and open the latest log stream, you can see the logs come in here.
There is lots of logs because I have tried to times when invoke these lambda function asynchronously.
But the idea is that you should see at least three location for the logs.
So because we invoke asynchronous way and interface to retry configuration, if you go to these configurations
of the lambda function and if you go to asynchronous invocation configuration, you can see the retry
attempt is to.
So that's why we have seen two, three times invocation logs when we hit the one invocation synchronous
or lambda function because we invoke asynchronous way and it is to retry configuration and that's why
it tries two times and got two times exceptions.
And after that, the third time when it gets again the same exception it is redirecting to destination
services.
So if you look at the lambda function, you can see the our destination is the Amazon case.
So you can go to Amazon and see the our destination record is come here or not open the Amazon case
and lambda Q We can click this, send the same message and see that we have one available message.
If you pull message from the case, we can see that we have one record.
It is added from the lambda for the execution logs.
You can see the details by adding open the body information.
If you scroll down, you can see the there is an error about the lambda error that we throw from the
lambda function.
So as you can see that we have successfully set our lambda destination and see the record from the Amazon
case.
But also we can also configure our lambda destination is on success.
You can open the lambda function and if you click the add destination, you can see that we can set
a on success and give the destination type as a topic ESC Lambda and even preach.
So this is how we can work with the asynchronous invocation and how we can set up the destinations.
And I would like to show another shortcut for this use case.
For example, we set a dedicated queue for this lambda function.
If there is an exception in two times we are adding the Amazon case, right?
This is the delta queue.
So we can also configure the data to queue, open the configuration and go to asynchronous invocation,
click the edit button.
And if you can see this here that the queue configuration can be set up in the asynchronous configuration.
For example, in here I can select the case and give the our name lambda queue and click this button.
This is exactly the same thing, what we have done in this video.
But I would like to focus to focus on to show you how we can add a destination to our lambda function.
Okay, very good.
Before closing the video, we should clear our resources for that purpose.
Please go to functions and delete functions.
Delete this lambda function.
And also we have create a record.
So please open the Amazon case and go to Qs and make sure that you have delete the Amazon six Q.
Look, we have successfully cleared our resources and we have successfully finished our use case, which
is the aid of Islam.
The destination escapes to the latter case.