In this video we are going to develop get all products method for product lambda microservices with
using dynamo DB client object from the SDK libraries.
So let's get started.
Before start, I would like to show you where we are using commands and libraries.
You can see that this is the SDK document for JavaScript three and we are using Dynamo DB Client Library
and this video we will use second command because we are going to get all products from the Dynamo DB
table.
In that case we will use the can command and see the input parameters in here and we will set these
kind of properties when interacting with second command.
So please open the widget to your code and go to index js file in the last video we implement get product.
This time we will implement get all products.
So please scroll down and after the gate product method we will implement get all products in here.
So for that purpose let me copy and paste and after that I will explain.
These methods, you can see that this is the get all products that we are using the asynchronous method
and in the first line we will log this operation and after that we are covering the three below to use
the Amazon cloud.
If there is an exception, we will see the logs on Amazon Cloud Logs.
That's why we covered the case below.
And we will prepare for the parameters and paste the parameters to the scan command and using the dynamic
DB client, send operation and return back the items and we log the items and return back the items
to the get all products method.
So now let's import required statements.
So for example, we will use dynamic DB client.
We have already import this statement.
You can come here and see at the beginning of the page we can see that we are using dynamic DB client
object and we have import Marshall and Marshall operation.
And if you scroll down this time we should import also a scan command.
We can come here, click the control space and import or I'm going to copy the scan command and go on
top of the page and put here comma and paste scan command.
So that means we are using scan command from the client base dynamic DB library.
So if you scroll down, you can see that this becomes green.
That means we have import successfully.
So in this stage I would like to emphasize that in here and also in the get product method, we are
getting the table name from the process environment dynamo DB table variable.
So that means this is the value comes from the environment.
Variables of the lambda function is you remember that when we have defined the lambda function we basically
create environment variables for the dynamo DB tables.
You can check for the product function, go to configuration, go to environment variables, see that
Dynamo DB table is here and value is a product.
So that means we will scan and also get item command in here in the table name parameter comes from
the lambda environment variables in here.
That's why we use Dynamo DB table name and process dot and we provide to get environment variables from
the lambda function and set in here.
Okay.
As you can see that we have develop get all products method and it is very similar to that product method.
The only difference is the command that we use second command in here for getting all products.
We use second command for getting one command.
We use get item command with placing the parameters.
So the idea is the same.
You should think the Dynamo DB is a great resource and Dynamo DB exposing APIs for these kind of actions.
And we call these APIs using the HDC package with to command objects and using the Dynamo DB client
send method.
So let's get started.
Implement other methods.