In this video, we are going to create a lambda function and configure Dynamo DB streams as an event
source of lambda function.
If you remember that a Lambda Invocation types, we use event source mapping, pulling in locations
when interacting with the dynamic DB streams because streams are using charts and Q mechanism like Amazon
Case and Kinesis.
So we will create a lambda function and create event source mapping pulling invocations between Lambda
and Dynamo.
DB For that purpose, please open the management console.
Go to Lambda and click the create function.
So I'm going to create a new function.
Which name is Native Order created function because these will be triggered when any order and item
in the Dynamo DB streams.
So if you scroll down, you can leave as it is for all the configurations.
But as you remember that we need to add a required permission if you open here and select the create
new role with the response template.
I would like to search for the Dynamo DB.
I know there is a Dynamo DB, but this is not stream.
So if you search for the streams.
So as you can see that there is no translated predefined policy.
For that purpose, I will create any role.
That means this is a default behavior and I'm leaving as it is all the configurations and after created
the function we will set a required permission with using the IAM.
Okay, please give the function name and leave as it is for all the configurations.
We will create a new with the basic lambda permission and click the create function button.
Our function is created successfully.
Now, the first thing we should do, that if you go to code section and come to the first line of our
Lambda function code, please add this line of code which is logging incoming event from the Dynamo.
The streams click to deploy button.
Okay.
Very good.
Now we should perform the important thing, which is the giving required permission to our lambda function.
As you remember that we mention about some of the permissions which required from the lambda when pulling
items from the Dynamo DB streams.
For that purpose, we will add a required permission into our execution world.
If you come here and click the configuration and go to permission, you remember that we have created
this lambda function with default configuration and it is creating a new execution role with basic permission.
There is only Amazon Cloud permission, but we also required some additional permission for Dynamo DB
streams, so Lambda needs some additional permission for that purpose.
I am going to go to this role from the IAM page and after that we will add required permission.
So which permission we have to request.
If you go back to our documentation and you can see that these permissions are required when it comes
to pulling from the Dynamo DB streams.
And I am looking for a policy which including these permissions.
So for that purpose we go back to our page and go to rules about our lambda function.
If you scroll down, you can see the permission tab and I'm going to add a new permission and attach
a policy.
So if you search here as a Lambda Dynamo DB execution rule and hit the enter, we can see that there
is a policy included from the A list.
This is the main manage policy.
If you open this policy, you can see the actions.
So these actions are regarding to dynamo DB streams that we are required these actions.
So that's why please select the Lambda Dynamo DB execution role and attach the policy.
Okay.
Police well successfully attest.
You can see the policy comes in here and if you come back to our lambda function and refresh the page,
open the page again, go to configuration permission.
And if you look at the resource summary, there is new actions come from the Dynamo DB.
If you look at the Dynamo DB actions, these are the stream related actions that we required when pulling
items from Dynamo DB streams.
So now we have only one configuration left.
If you look at our hands on lab, you can see that we should configure as a stream event source up to
a lambda.
So dynamo DB streams should be one source of a lambda.
We will create even source mapping to tell them the send records from our stream to the lambda function.
We can create multiple event sources mapping to process the same data with multiple lambda functions,
but we will choose the single lambda function and we will perform the event source mapping, pulling
in location with the lambda and the streams in order to configure our function to read from the Dynamo
DB streams, we have two options one for the adding trigger to Dynamo DB table.
Also, we can add trigger for the lambda function so we can both define in two ways and do all things
perform the same thing.
If you open the management console, go back to Amazon Dynamo DB table, if you go to open the table
and click the export streams and scroll down, we can see that stream enabled and we can edit it in
this place.
If you create a trigger, you can add the lambda function.
But I would like to choose.
Choose second way.
If you open the lambda function and we will add a trigger for the Dynamo.
DB If you click the trigger, we will select a source which is the Dynamo DB streams.
I'm searching for the Dynamo db oc so select the Dynamo DB table, which we will the order table and
we are selecting the enable trigger.
This will be enable trigger one whenever any item is create update or that it is we trigger to our lambda
function.
Here you can see the batch size.
Batch size is the number of the records that we will read from the lambda function when the stream happen.
So I'm leaving as it is and the starting position can be start latest.
This is the default one, but you can change for the trim horizontal.
So now I don't change any configuration of these are the sum configurations when receiving items from
the streams and this is the similar confirmations from the space because these are the related services
that using the event source mapping and pulling in locations that we can get the receive the items in
a batch mode and in the charts that we explain in the territorial sections.
So I'm leaving as it is all this configuration and you can see the additional settings in here.
So I am adding these dynamo DB streams into our lambda function.
Okay.
As you can see, the Dynamo DB comes in here.
If you scroll down, you can see the triggers comes in here and you can see the details.
These are the details of the Dynamo DB streams will be triggered to our lambda function and these are
the configurations.
And also if you go back to our Dynamo DB table, if you go to tables, open the order table and click
the export and streams and scroll down.
You can see that any trigger added in here when we add the lambda function, this is reflecting in the
in the dynamo db streams on the Dynamo DB of a management console.
So as you can see that we have successfully create a lambda function and configure dynamo db stream
is even source of lambda function.