1
00:00:00,180 --> 00:00:06,270
In this video we are going to develop lambda function for dynamic deviations is know that in the last

2
00:00:06,270 --> 00:00:13,560
video we are listed objects into the bucket and we are iterating these objects and add item into dynamic

3
00:00:13,560 --> 00:00:14,400
DB table.

4
00:00:14,850 --> 00:00:22,800
So for that purpose we will use dynamic DB client SDK package that we have already did in the last sections.

5
00:00:22,800 --> 00:00:25,860
So that's why I'm not going to explain detailed.

6
00:00:25,890 --> 00:00:33,330
We will install client dynamic DB and also we have utility library that we will use util dynamic DB.

7
00:00:33,690 --> 00:00:38,310
It is also very important to use Marshall and Marshall Operations to do that.

8
00:00:38,310 --> 00:00:42,540
Please open Visual Studio code and go to index case file.

9
00:00:42,720 --> 00:00:48,510
We are in here write item on the DB table with the incoming objects from the S3 bucket.

10
00:00:48,990 --> 00:00:55,470
So to perform these Dynamo DB actions before we start, we should add the required package into our

11
00:00:55,470 --> 00:00:56,640
Node.js module.

12
00:00:56,700 --> 00:01:02,460
As remember that this lecture folder will be our Node.js application that we will deploy on the Lambda

13
00:01:02,460 --> 00:01:03,210
functions.

14
00:01:03,210 --> 00:01:09,120
So now I'm going to run the NPM install command into our CLI.

15
00:01:09,150 --> 00:01:15,120
Please go to correct folder structure and run the NPM install commands one by one.

16
00:01:15,120 --> 00:01:20,520
The first one is the NPM install client dynamo DB package hit enter.

17
00:01:27,720 --> 00:01:28,030
Okay.

18
00:01:28,080 --> 00:01:34,020
The second one is the api install util dynamo db hit enter.

19
00:01:36,650 --> 00:01:42,400
And after that, please verify these two packages are imported successfully.

20
00:01:42,410 --> 00:01:49,970
If you go to package JSON file, you can see that these two client dynamo DB and line MDB installed

21
00:01:49,970 --> 00:01:50,960
successfully.

22
00:01:51,050 --> 00:01:55,190
Now we can use these libraries in order to interact with the dynamic DB.

23
00:01:55,370 --> 00:02:02,930
So for that purpose callback the index JS is know that when we interact in resources we need a client

24
00:02:02,930 --> 00:02:03,530
object.

25
00:02:03,560 --> 00:02:10,250
To do that we need also dynamic DB client JavaScript file, which is a separate Node.js module.

26
00:02:10,520 --> 00:02:16,130
In order to do that, come to our folder and create a new file.

27
00:02:16,130 --> 00:02:19,540
Which name is Dynamo DB Client Logs?

28
00:02:19,940 --> 00:02:22,880
So I'm going to copy and paste the codes.

29
00:02:23,210 --> 00:02:24,170
Let me copy paste.

30
00:02:24,200 --> 00:02:26,100
This is very similar with the H3 client.

31
00:02:26,120 --> 00:02:32,840
We basically export dynamo DB client from the dynamic DB client object of the client SDK library.

32
00:02:32,900 --> 00:02:39,530
So now if you come back to our indexes now we are ready to use our actual code and implement to Dynamo

33
00:02:39,530 --> 00:02:40,570
DB operations.

34
00:02:40,580 --> 00:02:45,350
But before that, let me change these S3 bucket operations.

35
00:02:45,680 --> 00:02:50,510
You remember that in the last video we are passing these parameters to the list, object, command and

36
00:02:50,510 --> 00:02:55,630
send this command to the client and it is return back to us data.

37
00:02:55,640 --> 00:02:57,610
So what data is coming to us?

38
00:02:57,620 --> 00:03:00,710
It is basically return to us object list.

39
00:03:00,710 --> 00:03:05,480
So I'm going to change the variable name as object list and also change the console log as the object

40
00:03:05,480 --> 00:03:05,950
list.

41
00:03:05,960 --> 00:03:13,790
So we got the object list from the Amazon S3 and we will iterate the object list to insert our dynamic

42
00:03:13,790 --> 00:03:14,660
DB table.

43
00:03:14,660 --> 00:03:20,980
So this is the first part that we finished and now we are going to contribute the second part.

44
00:03:20,990 --> 00:03:23,510
So let me copy in here.

45
00:03:23,510 --> 00:03:24,770
This is the first part.

46
00:03:25,310 --> 00:03:28,090
And now here you can see the second part.

47
00:03:28,100 --> 00:03:35,540
So in the second part we will iterate our object list and we will add item into Dynamo DB.

48
00:03:36,080 --> 00:03:42,590
As you remember that one S3 return vectors object list, it has the content array.

49
00:03:42,590 --> 00:03:47,690
So that's why we are writing the four condition for iteration in here.

50
00:03:47,690 --> 00:03:53,440
So in the fourth iteration we are going to iterate the contents array and get the content in a for loop.

51
00:03:53,450 --> 00:04:00,650
So in this loop, basically in the first line of code, we basically log the incoming content and after

52
00:04:00,650 --> 00:04:08,150
that we are preparing the parameters that we use in the put item command in Dynamo DB.

53
00:04:08,180 --> 00:04:10,610
So here you can find the parameters.

54
00:04:11,360 --> 00:04:17,690
So these parameters are including the table name and the item item will be the R content of the object

55
00:04:17,690 --> 00:04:22,370
list and we will pasting the whole content into bucket objects table.

56
00:04:22,550 --> 00:04:29,870
And we have some basic attribute values which are the remove undefined values true and convert clause

57
00:04:29,870 --> 00:04:31,120
instance to map true.

58
00:04:31,130 --> 00:04:38,390
So with these attributes we can pass the whole content object as item into bucket objects dynamo db

59
00:04:38,390 --> 00:04:39,080
table.

60
00:04:39,110 --> 00:04:45,560
After prepare the parameters, we basically send the request to the put item command.

61
00:04:45,710 --> 00:04:52,580
This time we will use put item command in here, passing the parameters as this way and put item command

62
00:04:52,580 --> 00:04:59,420
is provide to create a new item in dynamo DB table and use the DB client object to send this command

63
00:04:59,660 --> 00:05:07,720
available way to Amazon Dynamo DB and after that we will look to our created result and we finished

64
00:05:07,720 --> 00:05:08,930
the our code operations.

65
00:05:09,540 --> 00:05:10,130
Okay.

66
00:05:10,340 --> 00:05:17,570
Of course now we should not forget to record import statements as you know that we have import put item

67
00:05:17,570 --> 00:05:21,320
command we should import and also dynamo DB client object.

68
00:05:21,320 --> 00:05:27,320
If you go on top of these indexes file, let me write this import statement.

69
00:05:27,440 --> 00:05:29,750
This is for the put item command dynamo.

70
00:05:29,750 --> 00:05:38,060
DB And also we will use Marshall Command when preparing an item in the parameters and after that we

71
00:05:38,060 --> 00:05:40,460
will use Dynamo DB client object.

72
00:05:40,490 --> 00:05:42,260
Of course this is really important.

73
00:05:42,260 --> 00:05:46,070
This is separate Node.js module that we use the interactions of Dynamo.

74
00:05:46,070 --> 00:05:52,850
DB So these three import statements for Dynamo DB These two for the S three OC.

75
00:05:52,850 --> 00:05:58,070
Now, after preparing the import statement, if we scroll down and see that the command and Dynamo DB

76
00:05:58,070 --> 00:06:01,730
client is activated, let me explain from the secret.

77
00:06:02,090 --> 00:06:08,600
If you come back to our method, you can see that this is the 100 method for the lambda function and

78
00:06:08,600 --> 00:06:10,160
we have two main actions.

79
00:06:10,160 --> 00:06:15,920
The first one is list object into bucket and the second one right object into dynamo DB table.

80
00:06:16,400 --> 00:06:19,670
To perform the first object, we are preparing the parameters.

81
00:06:19,670 --> 00:06:22,460
We can move these parameters in here.

82
00:06:22,460 --> 00:06:26,090
Let me cut and paste in this line of code.

83
00:06:26,090 --> 00:06:31,910
So this line of code is performing the first task which is the list object into bucket.

84
00:06:31,910 --> 00:06:36,140
So that means we will interact with S3 client object and running to.

85
00:06:36,470 --> 00:06:39,230
Object command and get back to us.

86
00:06:39,230 --> 00:06:41,470
The objects into a bucket.

87
00:06:41,480 --> 00:06:42,980
The bucket name is in here.

88
00:06:42,980 --> 00:06:49,910
So what is most coming from the Amazon is three we can see in here in the last video we get this response.

89
00:06:49,910 --> 00:06:57,920
So they had a contents array and in the contents array it is listing the objects into Amazon S3 bucket.

90
00:06:57,920 --> 00:07:03,380
So we have one object and you can see the key and other attribute values in here.

91
00:07:03,380 --> 00:07:11,720
So that means these content zero which is these objects will be an item of dynamic DB table is you remember

92
00:07:11,720 --> 00:07:16,850
that when we create a dynamic DB table, we set the partition key as a key.

93
00:07:16,850 --> 00:07:21,710
So these objects including the key and the value of the text.

94
00:07:21,710 --> 00:07:28,520
So that means we can use these attributes and the partition K into our dynamic DB table.

95
00:07:28,520 --> 00:07:34,580
So that's why we can pass the whole object as an item of our application.

96
00:07:34,580 --> 00:07:41,810
You can see in here, if you scroll down, we are iterating the contents and we get prepare the parameters

97
00:07:41,810 --> 00:07:47,600
of the dynamic DB Put item command with passing the table name and also item in the item section.

98
00:07:47,600 --> 00:07:54,950
We passed the whole content object which including the key attribute and this is the ah partition partition

99
00:07:54,950 --> 00:07:59,330
key of the dynamic DB table, so that's why we can pass these as item.

100
00:07:59,330 --> 00:08:05,540
And after that, after preparing the parameters, we basically send the input item command with using

101
00:08:05,540 --> 00:08:10,400
the DB client in order to perform from creating an item into Dynamo DB table.

102
00:08:10,550 --> 00:08:15,590
So these are the our codes and we finish the development of these 100 method.

103
00:08:15,620 --> 00:08:18,530
Now we are going to perform local test.

104
00:08:18,530 --> 00:08:24,950
So I would like to verify our code is working or not with running the codes on my local computer.

105
00:08:24,950 --> 00:08:31,100
For that purpose, make sure that you have one handed method and at the end of this file you call this

106
00:08:31,100 --> 00:08:32,060
100 method.

107
00:08:32,090 --> 00:08:39,650
And after that we can open a new terminal and click the node command right to node command and passing

108
00:08:39,650 --> 00:08:40,850
our indexes.

109
00:08:40,850 --> 00:08:48,120
So this will be listing objects into bucket name of a bucket, and after that add an item in Dynamo

110
00:08:48,170 --> 00:08:48,950
DB table.

111
00:08:48,980 --> 00:08:51,590
Let's run this command and see what happens.

112
00:08:53,000 --> 00:08:55,970
As you can see that we have got successful response.

113
00:08:55,970 --> 00:09:02,570
If you scroll up and see what's going on, we can see that the first success message comes from the

114
00:09:02,570 --> 00:09:06,770
Amazon S3 and if you scroll down, you can see the content array.

115
00:09:06,770 --> 00:09:13,940
So the first array will be an item of our dynamic DB and in attributes they are key, last modified

116
00:09:13,940 --> 00:09:15,500
and e take and so on.

117
00:09:15,530 --> 00:09:20,600
The key attribute is the partition key of our table we can verify from dynamic.

118
00:09:20,600 --> 00:09:26,780
DB If you come to Dynamic DB tables, we have a bucket object table and the partition key is a key string.

119
00:09:27,260 --> 00:09:30,500
So that's why we can pass these value into items.

120
00:09:30,500 --> 00:09:35,390
And if you scroll down, the second response comes from the Amazon dynamic.

121
00:09:35,390 --> 00:09:43,610
DB That means we have successfully implement insert an item into dynamic DB table to verify that if

122
00:09:43,610 --> 00:09:50,210
you go back to console and open the bucket objects table and explore table items, if you run the second

123
00:09:50,210 --> 00:09:57,860
command, you can see that we have successfully insert an item which the key is a index.html and the

124
00:09:57,860 --> 00:10:00,890
other attributes comes from the successfully.

125
00:10:00,920 --> 00:10:07,340
These are the objects into the Amazon S3 that we return from the list object command.

126
00:10:07,340 --> 00:10:14,570
So now we have finished the development path and local test from the replication successfully.

127
00:10:14,570 --> 00:10:19,880
In the next video we are going to deploy our Node.js lambda function and invoke asynchronously from

128
00:10:19,880 --> 00:10:20,840
Amazon S3.
