1
00:00:00,270 --> 00:00:06,300
In this video, we are going to create a dynamic DB table with using our dynamic DB client object,

2
00:00:06,300 --> 00:00:11,030
which means using the SDK JavaScript version three.

3
00:00:11,040 --> 00:00:17,580
So we will use client dynamic DB package in order to perform create dynamic DB table operation.

4
00:00:17,670 --> 00:00:23,890
But before that, we should understand that which dynamic DB API we are going to invoke.

5
00:00:23,910 --> 00:00:29,590
For that purpose, I'm going to open the dynamic DB API reference documentation.

6
00:00:29,610 --> 00:00:36,690
If you go to actions create table, you can see that dynamic DB has create table API that we can invoke

7
00:00:36,690 --> 00:00:40,470
this API in order to create a table on Dynamic DB.

8
00:00:40,500 --> 00:00:47,250
And this is an asynchronous operation that we can create table and create table request.

9
00:00:47,250 --> 00:00:51,570
And this returns the immediate return response, which is the table.

10
00:00:51,570 --> 00:00:58,140
So this is creating and after the table created dynamic DB set the table so as active and if you scroll

11
00:00:58,140 --> 00:01:03,120
down you can see the expected request of these create table API.

12
00:01:03,270 --> 00:01:08,820
You can see that there is an attribute which is the attribute definition, billing mode, global secondary

13
00:01:08,820 --> 00:01:12,560
index, key schema, local secondary index and so on.

14
00:01:12,570 --> 00:01:20,760
So the important ones are attribute definitions and also key schema attribute definition is a set of

15
00:01:20,760 --> 00:01:24,030
attributes that describe the key schema for the table.

16
00:01:24,150 --> 00:01:26,880
And also there is a key schema.

17
00:01:27,510 --> 00:01:32,010
It is basically specifies the attributes that make up the primary key for a table.

18
00:01:32,010 --> 00:01:35,370
So that means it includes partition and sort key.

19
00:01:35,370 --> 00:01:42,270
So after that we will use provision throughput, which is the read and write capacity and we have to

20
00:01:42,270 --> 00:01:44,640
give table name and so on.

21
00:01:44,640 --> 00:01:48,300
So we will use these parameters when creating table.

22
00:01:48,300 --> 00:01:53,370
We will placing these parameters into the request of the create table command.

23
00:01:53,370 --> 00:02:01,920
So after we have understand our core dynamic DB API, we should also understand from the SDK package

24
00:02:01,950 --> 00:02:09,360
how we can invoke this package is you can see that we have a basic JavaScript documentation for dynamic

25
00:02:09,360 --> 00:02:15,060
DB client package and if you scroll down, we will follow these steps, which is the start with the

26
00:02:15,060 --> 00:02:17,070
installing required NPM package.

27
00:02:17,100 --> 00:02:21,000
And after that and after that we will import required packages.

28
00:02:21,000 --> 00:02:28,260
In our case we will import the DB client and after that we will use the create table command in our

29
00:02:28,260 --> 00:02:28,830
case.

30
00:02:28,830 --> 00:02:31,680
And after that we will follow these steps.

31
00:02:31,680 --> 00:02:35,070
First of all, we should create a dynamic DB client object.

32
00:02:35,100 --> 00:02:41,190
After that, we should create a parameters that required from the create table command and pasting these

33
00:02:41,190 --> 00:02:43,260
parameters to the command object.

34
00:02:43,260 --> 00:02:50,160
And after that we have to send these objects with using the client object, which is a dynamic DB client

35
00:02:50,160 --> 00:02:53,640
and send the command with including that parameters.

36
00:02:53,640 --> 00:03:00,960
So this is the common and the best practice for all interactions with dynamic DB one using the alias

37
00:03:01,050 --> 00:03:03,480
HDC for JavaScript version three.

38
00:03:03,480 --> 00:03:09,720
And this is the effective way for reducing costs and increasing the latency performance.

39
00:03:09,720 --> 00:03:13,710
And we will follow these steps when developing our create table command.

40
00:03:13,710 --> 00:03:20,310
So now let's follow these steps and create our Node.js module to perform this create table.

41
00:03:20,340 --> 00:03:25,800
I'm going to come the installing part and go back to our Visual Studio code.

42
00:03:25,830 --> 00:03:31,950
I have created a separate lecture for this video and I have added the design table text.

43
00:03:31,950 --> 00:03:38,280
So we are going to create an order table which has username part K and order date sort K.

44
00:03:38,280 --> 00:03:40,410
So we will implement this table.

45
00:03:40,410 --> 00:03:44,820
We're choosing to create a table command and using the SDK libraries.

46
00:03:44,850 --> 00:03:50,310
In order to do that, this table will be our Node.js module and perform the Create Table operation.

47
00:03:50,310 --> 00:03:57,180
So let me open our API reference documentation and as you can see that we will start with the installing

48
00:03:57,210 --> 00:03:58,170
required package.

49
00:03:58,170 --> 00:04:04,380
So we have verified that we are going to use this client dynamo DB package to interact with the Dynamo

50
00:04:04,380 --> 00:04:12,480
DB to do so, I have opened this Dynamo DB library package and copy this line of code and go to the

51
00:04:12,510 --> 00:04:16,380
our pseudocode and start a new terminal.

52
00:04:16,740 --> 00:04:19,200
So we will use section.

53
00:04:20,570 --> 00:04:24,260
20 and lecture 164.

54
00:04:24,470 --> 00:04:26,390
Okay, now copy paste this command.

55
00:04:26,420 --> 00:04:29,710
This will be installed required package for dynamic db interactions.

56
00:04:29,720 --> 00:04:30,730
Hit enter.

57
00:04:30,740 --> 00:04:34,430
So we will acting this folder as a Node.js application.

58
00:04:34,430 --> 00:04:41,990
So that's why it is mandatory that you should select the correct section and lecture folder.

59
00:04:41,990 --> 00:04:49,310
And we are going to create Node.js module package JSON and package LUXATION in this folder structure.

60
00:04:49,310 --> 00:04:54,980
So if you check the package JSON file, you can see the required dependencies added successfully.

61
00:04:54,980 --> 00:05:00,500
And if you check Node.js module, we have successfully required packages for the Dynamo DB operations.

62
00:05:00,500 --> 00:05:04,670
So now our package and installed successfully.

63
00:05:04,700 --> 00:05:10,970
If you come back to our documentation and scroll down, we need to follow this step.

64
00:05:10,970 --> 00:05:16,910
We should import required statement which is a dynamo DB client and related command object.

65
00:05:16,910 --> 00:05:21,050
But before that we should create a dynamic DB client object.

66
00:05:21,050 --> 00:05:27,290
So how we can create this dynamo DB client object, we can create this client object any JavaScript

67
00:05:27,290 --> 00:05:27,620
file.

68
00:05:27,620 --> 00:05:33,290
But the best practice is creating a separate a separate Node.js module.

69
00:05:33,410 --> 00:05:38,420
As you remember that in the last video we have created Dynamo DB Client JavaScript module.

70
00:05:38,420 --> 00:05:42,080
So I'm going to copy this script and paste into this file.

71
00:05:42,110 --> 00:05:49,550
So if you receive these codes, we basically use this import statement and we are using the Dynamo DB

72
00:05:49,550 --> 00:05:56,960
client into the our SDK and pasting the region information and create a Dynamo DB client object in this

73
00:05:56,960 --> 00:06:01,220
module in a separate module and exposing this dynamic DB client object.

74
00:06:01,250 --> 00:06:04,130
This is the best practice when it comes to interaction.

75
00:06:04,130 --> 00:06:06,110
This client object with the Dynamo.

76
00:06:06,110 --> 00:06:14,630
DB By this way, we can use these Node.js module any one of our application and we can load one time

77
00:06:14,630 --> 00:06:19,340
our client object and invoke several times with using the same client object.

78
00:06:19,340 --> 00:06:22,370
So now our client object is ready.

79
00:06:22,370 --> 00:06:28,040
If you come back to our documentation and scroll down, you can see that this time we are going to read

80
00:06:28,040 --> 00:06:31,070
to create a table operation.

81
00:06:31,070 --> 00:06:36,860
For that purpose, I'm going to create a new file which name is Create Table?

82
00:06:36,890 --> 00:06:41,000
So if you see that our application is going to be good.

83
00:06:41,000 --> 00:06:47,240
So I'm going to create a new JavaScript file which is the create table, but.

84
00:06:47,240 --> 00:06:54,290
JS And this will be the ah actual JavaScript file that we are going to invoke this file with Node command

85
00:06:54,290 --> 00:07:03,350
for example, I will run not create table but JS command when we have finished our code operation development

86
00:07:03,350 --> 00:07:09,530
and this will be interact with dynamic DB and create table for the order table on Dynamo DB.

87
00:07:09,560 --> 00:07:13,160
So now let's start the development for that purpose.

88
00:07:13,160 --> 00:07:14,540
I'm going to.

89
00:07:15,900 --> 00:07:19,740
Remove this PowerShell command and focus on the our developments.

90
00:07:19,740 --> 00:07:26,340
So basically, I will start with creating a basic function and invoke this function at the same file.

91
00:07:26,490 --> 00:07:32,450
As you can see that I have create a run method and call this method in the same file.

92
00:07:32,460 --> 00:07:35,700
So this is the the first thing that we should do.

93
00:07:35,700 --> 00:07:39,180
So as you can see that I have created a sync function.

94
00:07:39,180 --> 00:07:46,060
So that means this function should be a weight statement inside of their operations and I will start

95
00:07:46,060 --> 00:07:50,790
to try operation to perform these interactions.

96
00:07:50,790 --> 00:07:55,350
So basically the core of our implementation is in here.

97
00:07:55,380 --> 00:08:00,840
As you can see that I'm using a weight statement and using the dynamic DB client object in order to

98
00:08:00,840 --> 00:08:02,790
send this create table command.

99
00:08:02,790 --> 00:08:09,960
So this is the common structure and use this structure for every interaction when it comes to using

100
00:08:09,960 --> 00:08:11,460
a basic JavaScript.

101
00:08:11,460 --> 00:08:17,550
Version three, we should have client object that could be a client Saskia's event client.

102
00:08:17,550 --> 00:08:23,670
It doesn't matter, that should be a client object and this should send commands regarding to your ex.

103
00:08:24,120 --> 00:08:29,070
Our action is create table and we send the command with a particular parameters.

104
00:08:29,070 --> 00:08:37,740
That parameters should be include the table definitions, for example, table name attributes, partition

105
00:08:37,740 --> 00:08:39,120
and sort k and so on.

106
00:08:39,120 --> 00:08:45,810
So this line is the our main operation in the run method, create table method.

107
00:08:45,810 --> 00:08:49,320
So we will develop our function according to this line of code.

108
00:08:49,320 --> 00:08:54,930
So after this operation, I'm going to perform the log operations and finish the method.

109
00:08:54,990 --> 00:09:00,810
So as you can see that we have log in, create table and return back to this data information.

110
00:09:00,810 --> 00:09:02,810
That information should be included.

111
00:09:02,810 --> 00:09:08,550
The table is creating and table status should be the creating, as you remember, the documentation.

112
00:09:08,550 --> 00:09:12,570
And after that I'm going to log the error and finish this method.

113
00:09:12,660 --> 00:09:17,730
But there is also to do some things more.

114
00:09:17,730 --> 00:09:23,280
So we have finished our method, but this method using dynamic DB client object, right?

115
00:09:23,280 --> 00:09:29,280
First of all, we should import these client object into our create table JS function file.

116
00:09:29,280 --> 00:09:34,890
So if you come here and click the control space, you can see that the first line is importing the dynamic

117
00:09:34,890 --> 00:09:36,840
DB client module.

118
00:09:36,840 --> 00:09:43,020
But the important thing is we should explicitly say that JS otherwise it won't be work.

119
00:09:43,020 --> 00:09:47,310
This is very important when it comes to using Node.js functions.

120
00:09:47,310 --> 00:09:56,130
So we have imported required statement, which is a dynamic DB jazz and also we have continued our operations

121
00:09:56,130 --> 00:10:03,720
dynamo DB client can be sent now because the DB client comes from the DB client JavaScript external

122
00:10:03,720 --> 00:10:06,690
module and is exporting dynamic DB client.

123
00:10:06,870 --> 00:10:13,860
By this way, we can use this module into our main application and we basically send create table command.

124
00:10:13,860 --> 00:10:20,190
If you come here, you can see that these create table commands comes from the client dynamic DB package.

125
00:10:20,190 --> 00:10:23,430
So that's why we have to import these statement.

126
00:10:23,430 --> 00:10:30,390
So by this way, if you scroll, come here and click the control space, you can see that we have importing

127
00:10:30,390 --> 00:10:33,510
record package tables in here.

128
00:10:33,510 --> 00:10:35,280
So create table class.

129
00:10:35,280 --> 00:10:40,620
It comes from the client dynamic DB HDC package and we also import this statement.

130
00:10:40,620 --> 00:10:44,700
So make sure that you have import this statement successfully after that.

131
00:10:44,700 --> 00:10:47,580
One thing is missing, which is the parameters.

132
00:10:47,580 --> 00:10:53,520
What is the parameters for this create table operations is you remember that when we look at the actual

133
00:10:53,520 --> 00:11:00,600
dynamic DB API reference, we have a create table and it is requiring this kind of syntax that we can

134
00:11:00,600 --> 00:11:02,070
provide in the parameters.

135
00:11:02,070 --> 00:11:11,130
So for that purpose, let's come here and create a parameters object at the beginning of the method

136
00:11:11,130 --> 00:11:14,970
and specify the required parameters.

137
00:11:14,970 --> 00:11:21,900
So let me copy, paste and explain why one by one is you can see that I have created a parameters object

138
00:11:21,900 --> 00:11:27,120
in here and this is a JSON object, including lots of configuration parameters.

139
00:11:27,120 --> 00:11:30,330
For example, the first one is the attribute definition.

140
00:11:30,480 --> 00:11:34,920
Attribute definitions is an array of attributes of our dynamic DB table.

141
00:11:34,920 --> 00:11:39,180
So as you remember that we have designed table with the username and order date.

142
00:11:39,180 --> 00:11:44,310
So that's why in the create table of the parameters we are placing the attribute name, username and

143
00:11:44,310 --> 00:11:45,030
order date.

144
00:11:45,180 --> 00:11:49,050
After that, another important parameter is key schema.

145
00:11:49,110 --> 00:11:53,190
Key schema is the specifies the partition and sort k.

146
00:11:53,220 --> 00:11:56,880
So that's why we are placing the attribute name also key type.

147
00:11:57,000 --> 00:12:00,930
Key type hash means partition key range means sort key.

148
00:12:00,930 --> 00:12:08,070
So after we have defined attributes and key schemas, we should provide the table name this mandatory

149
00:12:08,790 --> 00:12:13,620
mandatory configuration and we can also set the read write capacity.

150
00:12:13,740 --> 00:12:14,880
You can know these.

151
00:12:15,260 --> 00:12:17,720
Recovers from the adults management console.

152
00:12:17,730 --> 00:12:24,810
When we create a new dynamic DB table, we have to specify these key schema attributes and retry capacity

153
00:12:24,810 --> 00:12:26,190
table name and so on.

154
00:12:26,190 --> 00:12:28,800
And also we set the stream enabled false.

155
00:12:28,800 --> 00:12:32,190
So these are the configurations for the create table operation.

156
00:12:32,190 --> 00:12:38,400
So that's why in the parameters object, we placing these parameters objects into the create table command.

157
00:12:38,400 --> 00:12:42,240
In order to create table, we using the dynamic DB client object.

158
00:12:42,600 --> 00:12:43,320
Okay.

159
00:12:43,350 --> 00:12:47,370
I think we have finished the our coding part now we can run this code.

160
00:12:47,370 --> 00:12:54,930
So for that purpose I'm going to open the terminal and go to related folder file.

161
00:12:56,550 --> 00:12:57,420
Okay.

162
00:12:59,280 --> 00:13:01,020
Now we can run the node command.

163
00:13:01,020 --> 00:13:06,930
So this is very important when it comes to using the node modules, we can run the node command and

164
00:13:06,930 --> 00:13:09,360
I'm going to pasting the create table.

165
00:13:09,630 --> 00:13:15,870
JS So this command will provide to run our create table JavaScript file.

166
00:13:15,870 --> 00:13:21,660
And this code is running this run method and run method using the dynamic DB client object.

167
00:13:21,660 --> 00:13:29,070
So this object is the region of the US is to of my aid account and after that sending the create table

168
00:13:29,070 --> 00:13:30,720
command with the specific parameters.

169
00:13:30,720 --> 00:13:37,380
So that means this will be create a dynamic DB table or my a account on the US is to region.

170
00:13:37,380 --> 00:13:42,570
So let's run this command on the correct folder pet and hit enter.

171
00:13:42,990 --> 00:13:49,320
So see that we got the exception which is the import statement it cannot understand import statement.

172
00:13:49,560 --> 00:13:55,860
We have to set type module into package JSON file in order to gain is six scripts.

173
00:13:55,860 --> 00:14:01,260
So go to package JSON files and come here and set the type as a module.

174
00:14:02,420 --> 00:14:07,590
So now it should be work because we are using the secret models.

175
00:14:07,610 --> 00:14:13,250
And if you come back to our create table and come here, run the same command, hit the enter.

176
00:14:14,390 --> 00:14:20,360
As you can see that this time we can successfully create table from our local computer to interact with

177
00:14:20,360 --> 00:14:23,840
the aid package for the create operation.

178
00:14:23,870 --> 00:14:26,030
You can see the table description in here.

179
00:14:26,070 --> 00:14:32,450
Table service comes creating, as you remember, that this is a asynchronous API that we can create

180
00:14:32,450 --> 00:14:35,420
table and this will be returned to table.

181
00:14:35,520 --> 00:14:39,680
This is creating after it is created table on dynamic DB table.

182
00:14:39,680 --> 00:14:40,920
So this will be created.

183
00:14:40,940 --> 00:14:48,260
To verify that, please open the measurement console and go to dynamic DB and open the tables and see

184
00:14:48,410 --> 00:14:53,300
our order table is created or not see that we have successfully create our order table.

185
00:14:53,300 --> 00:14:56,180
So this is active partition key is username.

186
00:14:56,180 --> 00:14:58,580
So K is order date and everything.

187
00:14:58,580 --> 00:15:00,340
Same is our expert.

188
00:15:00,620 --> 00:15:07,580
So as you can see that all the table created as we develop with the HDC, we use create table command

189
00:15:07,580 --> 00:15:11,210
with placing required parameters and send dynamic DB.

190
00:15:11,420 --> 00:15:15,410
We are using the client object to perform Dynamic DB operations.
