In this video, we are going to developing our lambda function.
So the first step is we are listing objects into the bucket.
So that means think about that with the incoming event JSON object, we can get the bucket name and
after that in the lambda function, we will interact with the Amazon S3 passing the bucket name and
get the object from the bucket.
We're using a WS SDK package, so let's get started.
Please open the index JS file.
So I'm going to listing objects in the bucket name.
So that means I have the interaction with the S3 client object.
And for that purpose we are going to use these list object version two command.
So you can see the example in here.
We can come here and see the list object version two command and this is the example we will implement
this example.
So let me start to developing first.
First of all, I'm going to develop try case block.
We can come here and from the cache block.
Now in the tribe.
Look, we basically use a steady client and center list object version to command.
Let me develop these codes.
So as you remember that these are the almost the same steps when we have interaction with the client.
The only difference is we are developing the handle method, which is the lambda function code.
But the idea is the same.
We are using the client and sent to this object version to command with the parameters.
Also, I'm going to create the parameters and after that we are logging the incoming data from the H3.
Okay, now let me continue with developing the parameters.
So we should define the parameters in here.
Basically, in the parameters we should provide the bucket name.
We can check the list object version to command request.
The only important object is the bucket.
I'm placing the bucket name in here in the previous.
In the next videos we will get this bucket name from the incoming event JSON.
But this time I would like to show with the hardcoded and give the bucket name and paste the parameters
in here in the list object command and send the data with S3 client.
So that means we have performed the first step listing object in the bucket, but please don't forget
that required package.
Please come here and import required packets for that purpose I'm going to import one by one.
Let me go on top of these indexes and import this statement.
So we will import list, object command and also import client separate Node.js module and don't forget
to add the JS extension, otherwise it won't be work.
Okay.
So now I would like to test this code in my local computer.
Even we develop the Lambda 100 code before we deploy these methods and these codes into lambda function.
We can test and verify the codes and into our local computer.
In order to do that, I'm going to copy this hundred method and.
At the end of these indexes, I am going to invoke and call these one methods.
So first of all, I'm calling this handle method and after that I will use note command as we did before.
So this is the good practice with using the note command.
With the note command, we can verify that this function is working fine or not.
And after that, we should command this 100 method and zip this file and deploy the lambda function.
But since that time we can perform our local test to running the note commands.
If you open the our.
Command window.
You can run the mode, command and paste the indexes.
So this will be run these indexes and go to 100 method.
In the handle method, we basically perform that communicating with S3 listing to objects into the bucket,
which the given name of this one.
So let's hit enter and try to test these code.
Yes.
As you can see that we have successful test.
Basically request seems either undefined because we don't passing any event JSON, but we can also paste
this event JSON into our application.
But after that, we basically get the success response from the S3 client object.
You can come here and see the service code and see the content in here.
So in the S3 bucket of this name of the bucket, there is a key index, HTML file and you can see the
other attributes and there is only one column, one object into this bucket.
So as you can see that we have successfully performed our local test before deploying this application.
So this is the our way of working and development of the Lambda development approach.
First we verify it is working our local computer with the node command and after that we will compress
and deploy our code to the lambda function and test with the real locations.
After verify our function code, let's review our function code.
If you scroll down and see that basically it is returning a response as a subsequent 200.
So if you look at our one method, you can see that we are returning helo response, which is status
code of 200, but we don't need to return any code from our function because we are asynchronous function
that triggers from the Amazon S3 so we don't need to return value for that purpose.
I'm going to remove these all return statement and come here.
And we basically covered the cache block and in the case block we can log the error if there is an error,
and that's all.
So for our 100 method, we don't need to return any synchronous response because we are triggering from
S3 asynchronously.
As you can see that we have only try catch block and log the asynchronous operation that we can understand
what's happening in this function code.
So we have already test this code with the node command you can run again and test your index JS and
see that our objects listed from the bucket name and we are ready for to continue the second operation.
So in the next video we are going to iterate these bucket objects and write these bucket objects on
the Dynamo DB table.