In this video, we are going to create infrastructure for Amazon S3, Lambda and A.B. to perform our
hands on loop.
So we will use a management console to create a lambda function and configure a trigger for Amazon S3
The trigger invokes our function every time when we add an object into our Amazon S3 bucket.
So let's get started.
In order to do that, I'm going to start with creating a bucket.
Please open the engine console.
Go to Amazon S3.
We will create a bucket.
Create Amazon S3 bucket and upload a test file to our new bucket.
So go to buckets and click the create bucket.
And give the name these buckets.
I'm going to give a bucket and give the random name to make it unique and select the region.
If you scroll down.
I'm not leaving.
I'm not changing any conversation.
Leave as it is all this configuration and click to create bucket button.
Look, as you can see that we have success to create a steady bucket.
And if you open the bucket, we don't have any object.
I'm not going to upload any object.
No, because we will create a lambda function that triggered when uploading S3 bucket.
So that's why let's go to the lambda functions, open the lambda function page and I'm going to create
a new function.
And author from The Secret and they give the function name is a function.
If you continue to configure our lambda function, you can see the runtime is node.js and architecture
is leave this for the permissions are important we should change the permission because if you expand
these change default execution role, the default execution rule settings is creating any role with
the basic lambda permission.
But these lambda function will be interact with the S3 and Dynamo DB.
If you come back to our picture, you can come here and see in here or lambda function will be triggered
from the Amazon S3 and interact with the Dynamo DB to insert file metadata in Dynamo DB.
So Lambda function should require permissions to invoke S3 and also access dynamic DB to do that in
here.
When we creating Lambda function, we create a new rule from the policy template.
If will remember that a place has some predefined policy templates that we can give this policy template.
So for example C give the row name as a three function rule and see the policy templates.
When we interact any dynamic DB resource from the lambda function, we should select the simple microservice
permission.
This will be part from crud operations from the lambda function.
This is our Dynamo DB integration, but we have also required S3, S3 related permissions.
You can see in here Amazon S3 Object Read only permission.
So we can give these S3 written permission because also in the Lambda function, we can reach the S3
and read some bucket and objects from the S3 in the Lambda function code.
That's why it is required these policies also OC after edit these two policy and we are going to create
new role for our newly created function.
Which name is S3 function?
So make sure that you have selected these.
Create a new role from a policy.
Give the role name and after that select the policy.
Simple Microsoft's permission for Dynamic DB Amazon S3 Object Read only permission for the Amazon S3
interaction in Lambda Function Code and after that, click the create function.
So this will take some time to creating role with these policies and also this lambda function.
It is successfully created.
If you scroll down and come to the configuration and permissions, you can see that we have successfully
create a three functional.
And if you select the function resource summary, we can see the Amazon Dynamo DB comes in here which
performing all operations and also we can see Amazon S3 for allowing to get object actions.
Okay, very good.
So if you come back to our code path now, we can develop our function.
But before that I'm going to only adding the log to see incoming log from the Amazon S3.
Please add this line of code at the beginning of the Lambda function and I am not going to implement
the function code itself.
Now before that, it is good to understand which incoming event comes from the one the asynchronous
invoke from the Amazon S3.
So click to deploy and update the function code.
We have added log to see incoming event from S3 one asynchronous invocation.
So now it is time to very important configuration, which is the trigger.
When you open the S3 function, you can see the trigger button comes in here, click this trigger and
we can select a source.
In our case, this lambda function is triggered from the Amazon S3 so that's why we are going to select
the S3.
And after that it is requesting us the HTC bucket name.
If you come here you can see that this is the name of the edit created bucket name.
Select this bucket name and here you can see the event type.
This is the important because we would like to trigger our lambda function when any object uploaded
to this S3 bucket.
So run the upload, perform in the bucket.
This will be the put operation maybe you remember put object command is using when uploading S3 bucket
so that's why select even time as a put this is very important so I don't add any optional prefix or
suffix and we don't any recursive invocations.
So it is also important.
So that's why we should check this statement and make sure that we don't have any recursive invocations
and we have give the acknowledgement about this checkbox and click add button.
So as you can see that the trigger is a bucket was successfully added to the function which is our function
now to trigger from the S3 bucket.
And the function is now receiving events from the trigger, which is the bucket.
So if you come here and click the configuration and triggers, you can also see the details in here.
The trigger bucket is S3 bucket dash these number and if you click the details, you can see the old
details about the bucket name.
That means we have done with the lambda create operation.
These is the permissions and triggers are adding successfully.
Now I'm going to create Dynamo DB as you know that we are continuing with the creating infrastructure
on this environment.
This is the first step.
So that's why I'm going to create resources first collected IMDB and click the table.
So table name should be the bucket objects.
We will store the bucket objects metadata in this table.
So that's why I'm giving this table name.
After that, we can set the partition key.
Partition key should be the key.
So this is so important.
Please set the key as a partition key because we will pass the incoming bucket objects from the Amazon
S3 to Dynamo DB table for that purpose.
If you look at the S3 JSON format, you can see that this is the object JSON object for the bucket objects.
That means it is including key and other attributes.
We will got this key as a passing key and string value.
That means we will pass this item into the Dynamo DB table.
Which name is bucket object?
So after set the partition key is a key.
I'm not going to set cert key and we can set the customize settings in order to make copies more on
demand.
And I'm not going to change any other configuration leave as it is and click the create table button.
You can see that we have created the infrastructure for Amazon S3, a Lambda and Dynamo DB.
Now it is time to develop our Lambda function for asynchronous invocation from Amazon S3.
Read data from Amazon S3 and persist on Dynamo DB table.