In this video, we are going to create a lambda function.
It is lambda is one competing rather than an imperative model.
So events will compete in response to events.
When the event source happens, it triggers the lambda function.
The event source will be the API gateway in this case, and the source could be the request of End Point,
which will go through later the API gateway and then the execute to incoming event and interacting with
Dynamo DB to perform CRUD operations.
So we create a lambda function for the back end of our API.
This lambda function creates reads, updates and deletes items from dynamic DB.
The function uses events from the API gateway to determine how to interact with the Dynamo DB.
So in order to create lambda function, please open the mission console, go to a lambda and choose
create function button.
After that we will create a function from scratch.
To do that, I'm going to give the name as a function, as a product function, because we are using
the implementing product microservices.
So if you scroll down, the runtime will be Node.js and leave as it is the other complications.
But if you expand the permissions, so under the permissions type this time we will change default execution
role and we can select the create a new role from a policy template.
So let me select this new role with a WS post template.
After that, if you scroll down, it is requiring a role information role name.
So I'm going to provide the role name as a product role.
And for policy templates, we can choose simple Microsoft's permission, because if you expand this
one here, you can see the different policy templates that manage by the yes.
So we are going to select simple Microsoft's permission.
If you select this one, you can see that it is regarding to Dynamo.
DB So that means this policy grants the Lambda function permissions to interact with Dynamo DB in order
to perform perturbations.
If you scroll down, you can see that we have added a simple Microsoft permission to create role name,
which is the product role, and we use a manage policy for simplicity as a best practice.
We should create our own IAM policy to grant the minimum permissions required, but this time it is
good to use managed policy in a yes by the one creating this lambda function.
Because if you look at the architecture lambda function, interact with the Dynamo DB and it is requiring
the permissions and it is managed by the A.
S.
So that's why when we are creating lambda function, we can create a new role with assigning these dynamo
DB policies, performing the cross operations.
Look, let's create a function.
A lambda function is created successfully.
So now I am going to develop our lambda function.
But this time I'm going to copy, paste this function and let me show how we can best please go to the
pseudocode and go to the Section 17 and lecture 143 and open indexes.
Let's right click copy this code and paste into our Lambda Function code.
So click the deploy button.
So please don't consider how we can write this function in this stage, because we will write these
code step by step and be together in the upcoming lectures.
For now, please download and copy from the video resources and paste into here.
So basically if we explain a little bit, so the handle method is the method that will be executed,
the lambda function and the function takes to object.
As you remember that the event object contains all of the data sent from the event source and the context
object provides several methods and properties and we have copied the snippet code and paste into the
indexes by using the event HTTP method.
You can see in here we want that method to differentiate the HTTP request which comes from the API gateway
and we can basically perform, create, update, delete and retrieve operations with dynamic DB using
the SDK package.
And I will explain these codes and develop with the latest libraries in the upcoming videos.
But this time I'm going to copy and paste to accommodate the incoming request from the API gateway and
you can think that we are using the dynamic DB async package to perform CRUD operations.