In this video, we are going to create a dynamic DB table with using our dynamic DB client object,
which means using the SDK JavaScript version three.
So we will use client dynamic DB package in order to perform create dynamic DB table operation.
But before that, we should understand that which dynamic DB API we are going to invoke.
For that purpose, I'm going to open the dynamic DB API reference documentation.
If you go to actions create table, you can see that dynamic DB has create table API that we can invoke
this API in order to create a table on Dynamic DB.
And this is an asynchronous operation that we can create table and create table request.
And this returns the immediate return response, which is the table.
So this is creating and after the table created dynamic DB set the table so as active and if you scroll
down you can see the expected request of these create table API.
You can see that there is an attribute which is the attribute definition, billing mode, global secondary
index, key schema, local secondary index and so on.
So the important ones are attribute definitions and also key schema attribute definition is a set of
attributes that describe the key schema for the table.
And also there is a key schema.
It is basically specifies the attributes that make up the primary key for a table.
So that means it includes partition and sort key.
So after that we will use provision throughput, which is the read and write capacity and we have to
give table name and so on.
So we will use these parameters when creating table.
We will placing these parameters into the request of the create table command.
So after we have understand our core dynamic DB API, we should also understand from the SDK package
how we can invoke this package is you can see that we have a basic JavaScript documentation for dynamic
DB client package and if you scroll down, we will follow these steps, which is the start with the
installing required NPM package.
And after that and after that we will import required packages.
In our case we will import the DB client and after that we will use the create table command in our
case.
And after that we will follow these steps.
First of all, we should create a dynamic DB client object.
After that, we should create a parameters that required from the create table command and pasting these
parameters to the command object.
And after that we have to send these objects with using the client object, which is a dynamic DB client
and send the command with including that parameters.
So this is the common and the best practice for all interactions with dynamic DB one using the alias
HDC for JavaScript version three.
And this is the effective way for reducing costs and increasing the latency performance.
And we will follow these steps when developing our create table command.
So now let's follow these steps and create our Node.js module to perform this create table.
I'm going to come the installing part and go back to our Visual Studio code.
I have created a separate lecture for this video and I have added the design table text.
So we are going to create an order table which has username part K and order date sort K.
So we will implement this table.
We're choosing to create a table command and using the SDK libraries.
In order to do that, this table will be our Node.js module and perform the Create Table operation.
So let me open our API reference documentation and as you can see that we will start with the installing
required package.
So we have verified that we are going to use this client dynamo DB package to interact with the Dynamo
DB to do so, I have opened this Dynamo DB library package and copy this line of code and go to the
our pseudocode and start a new terminal.
So we will use section.
20 and lecture 164.
Okay, now copy paste this command.
This will be installed required package for dynamic db interactions.
Hit enter.
So we will acting this folder as a Node.js application.
So that's why it is mandatory that you should select the correct section and lecture folder.
And we are going to create Node.js module package JSON and package LUXATION in this folder structure.
So if you check the package JSON file, you can see the required dependencies added successfully.
And if you check Node.js module, we have successfully required packages for the Dynamo DB operations.
So now our package and installed successfully.
If you come back to our documentation and scroll down, we need to follow this step.
We should import required statement which is a dynamo DB client and related command object.
But before that we should create a dynamic DB client object.
So how we can create this dynamo DB client object, we can create this client object any JavaScript
file.
But the best practice is creating a separate a separate Node.js module.
As you remember that in the last video we have created Dynamo DB Client JavaScript module.
So I'm going to copy this script and paste into this file.
So if you receive these codes, we basically use this import statement and we are using the Dynamo DB
client into the our SDK and pasting the region information and create a Dynamo DB client object in this
module in a separate module and exposing this dynamic DB client object.
This is the best practice when it comes to interaction.
This client object with the Dynamo.
DB By this way, we can use these Node.js module any one of our application and we can load one time
our client object and invoke several times with using the same client object.
So now our client object is ready.
If you come back to our documentation and scroll down, you can see that this time we are going to read
to create a table operation.
For that purpose, I'm going to create a new file which name is Create Table?
So if you see that our application is going to be good.
So I'm going to create a new JavaScript file which is the create table, but.
JS And this will be the ah actual JavaScript file that we are going to invoke this file with Node command
for example, I will run not create table but JS command when we have finished our code operation development
and this will be interact with dynamic DB and create table for the order table on Dynamo DB.
So now let's start the development for that purpose.
I'm going to.
Remove this PowerShell command and focus on the our developments.
So basically, I will start with creating a basic function and invoke this function at the same file.
As you can see that I have create a run method and call this method in the same file.
So this is the the first thing that we should do.
So as you can see that I have created a sync function.
So that means this function should be a weight statement inside of their operations and I will start
to try operation to perform these interactions.
So basically the core of our implementation is in here.
As you can see that I'm using a weight statement and using the dynamic DB client object in order to
send this create table command.
So this is the common structure and use this structure for every interaction when it comes to using
a basic JavaScript.
Version three, we should have client object that could be a client Saskia's event client.
It doesn't matter, that should be a client object and this should send commands regarding to your ex.
Our action is create table and we send the command with a particular parameters.
That parameters should be include the table definitions, for example, table name attributes, partition
and sort k and so on.
So this line is the our main operation in the run method, create table method.
So we will develop our function according to this line of code.
So after this operation, I'm going to perform the log operations and finish the method.
So as you can see that we have log in, create table and return back to this data information.
That information should be included.
The table is creating and table status should be the creating, as you remember, the documentation.
And after that I'm going to log the error and finish this method.
But there is also to do some things more.
So we have finished our method, but this method using dynamic DB client object, right?
First of all, we should import these client object into our create table JS function file.
So if you come here and click the control space, you can see that the first line is importing the dynamic
DB client module.
But the important thing is we should explicitly say that JS otherwise it won't be work.
This is very important when it comes to using Node.js functions.
So we have imported required statement, which is a dynamic DB jazz and also we have continued our operations
dynamo DB client can be sent now because the DB client comes from the DB client JavaScript external
module and is exporting dynamic DB client.
By this way, we can use this module into our main application and we basically send create table command.
If you come here, you can see that these create table commands comes from the client dynamic DB package.
So that's why we have to import these statement.
So by this way, if you scroll, come here and click the control space, you can see that we have importing
record package tables in here.
So create table class.
It comes from the client dynamic DB HDC package and we also import this statement.
So make sure that you have import this statement successfully after that.
One thing is missing, which is the parameters.
What is the parameters for this create table operations is you remember that when we look at the actual
dynamic DB API reference, we have a create table and it is requiring this kind of syntax that we can
provide in the parameters.
So for that purpose, let's come here and create a parameters object at the beginning of the method
and specify the required parameters.
So let me copy, paste and explain why one by one is you can see that I have created a parameters object
in here and this is a JSON object, including lots of configuration parameters.
For example, the first one is the attribute definition.
Attribute definitions is an array of attributes of our dynamic DB table.
So as you remember that we have designed table with the username and order date.
So that's why in the create table of the parameters we are placing the attribute name, username and
order date.
After that, another important parameter is key schema.
Key schema is the specifies the partition and sort k.
So that's why we are placing the attribute name also key type.
Key type hash means partition key range means sort key.
So after we have defined attributes and key schemas, we should provide the table name this mandatory
mandatory configuration and we can also set the read write capacity.
You can know these.
Recovers from the adults management console.
When we create a new dynamic DB table, we have to specify these key schema attributes and retry capacity
table name and so on.
And also we set the stream enabled false.
So these are the configurations for the create table operation.
So that's why in the parameters object, we placing these parameters objects into the create table command.
In order to create table, we using the dynamic DB client object.
Okay.
I think we have finished the our coding part now we can run this code.
So for that purpose I'm going to open the terminal and go to related folder file.
Okay.
Now we can run the node command.
So this is very important when it comes to using the node modules, we can run the node command and
I'm going to pasting the create table.
JS So this command will provide to run our create table JavaScript file.
And this code is running this run method and run method using the dynamic DB client object.
So this object is the region of the US is to of my aid account and after that sending the create table
command with the specific parameters.
So that means this will be create a dynamic DB table or my a account on the US is to region.
So let's run this command on the correct folder pet and hit enter.
So see that we got the exception which is the import statement it cannot understand import statement.
We have to set type module into package JSON file in order to gain is six scripts.
So go to package JSON files and come here and set the type as a module.
So now it should be work because we are using the secret models.
And if you come back to our create table and come here, run the same command, hit the enter.
As you can see that this time we can successfully create table from our local computer to interact with
the aid package for the create operation.
You can see the table description in here.
Table service comes creating, as you remember, that this is a asynchronous API that we can create
table and this will be returned to table.
This is creating after it is created table on dynamic DB table.
So this will be created.
To verify that, please open the measurement console and go to dynamic DB and open the tables and see
our order table is created or not see that we have successfully create our order table.
So this is active partition key is username.
So K is order date and everything.
Same is our expert.
So as you can see that all the table created as we develop with the HDC, we use create table command
with placing required parameters and send dynamic DB.
We are using the client object to perform Dynamic DB operations.