1
00:00:00,240 --> 00:00:06,930
In this video, we are going to developing product method for product lambda microservices with using

2
00:00:06,930 --> 00:00:12,720
Dynamo DB client objects in Adobe's SDK Version three libraries.

3
00:00:13,170 --> 00:00:14,730
So let's get started.

4
00:00:15,090 --> 00:00:18,870
To do so, please open the Visual Studio code and come to our actual logic.

5
00:00:19,140 --> 00:00:22,700
As you remember that we have right this switch statement in the previous video.

6
00:00:22,710 --> 00:00:25,710
So this video we will implement get product method.

7
00:00:25,710 --> 00:00:29,360
That means we are passing the ID information from the parameters.

8
00:00:29,370 --> 00:00:33,090
This will be the gate product by ID operation.

9
00:00:33,090 --> 00:00:40,020
So let me start developing and I will explain after that, I'm going to remove this one and create a

10
00:00:40,020 --> 00:00:40,860
method body.

11
00:00:40,890 --> 00:00:47,460
You can see that this is the our method, but it is using the keyword and it is getting product ID as

12
00:00:47,460 --> 00:00:48,270
a parameter.

13
00:00:48,300 --> 00:00:52,920
And we will query our product table with looking this product ID.

14
00:00:53,610 --> 00:00:55,860
So first of all, I would like to look.

15
00:00:56,790 --> 00:01:00,570
The method and we will insert the gate product method.

16
00:01:00,630 --> 00:01:07,350
And after that I'm going to write it like each block because we will perform the action of.

17
00:01:08,710 --> 00:01:11,020
Communicate it to dynamo DB client object.

18
00:01:11,350 --> 00:01:17,710
So before that it is good to cover we try catch block OC in the trial.

19
00:01:17,710 --> 00:01:23,290
Look basically we will interact with the dynamo DB client object to perform get item command.

20
00:01:23,290 --> 00:01:30,220
So when we interact dynamo DB client object to send get item command, we have two items to develop.

21
00:01:30,250 --> 00:01:36,190
The first one is to create parameters and paste the parameters to the get item command and send this

22
00:01:36,190 --> 00:01:36,490
command.

23
00:01:36,520 --> 00:01:39,340
Be using Dynamo DB client object for that purpose.

24
00:01:39,340 --> 00:01:41,860
Let me copy, paste and explain after that.

25
00:01:41,860 --> 00:01:48,670
So you can see that these are the are parameters to the get item command and we paste this command into

26
00:01:48,670 --> 00:01:52,750
get item command and this will be sent with using to Dynamo DB client object.

27
00:01:53,050 --> 00:02:01,540
After that we will console this item which comes from the Dynamo DB and log this item and return this

28
00:02:01,540 --> 00:02:02,080
item.

29
00:02:02,530 --> 00:02:03,190
Okay.

30
00:02:03,190 --> 00:02:06,400
So we should not forget to add import statement.

31
00:02:06,400 --> 00:02:07,630
We use some libraries.

32
00:02:07,630 --> 00:02:12,270
For example, the first library is Marshall and Marshall operation is.

33
00:02:12,280 --> 00:02:18,820
Remember that these are the utilities for Dynamo DB to simplify these key information without pasting

34
00:02:18,820 --> 00:02:19,960
any data type.

35
00:02:19,960 --> 00:02:27,130
So here you can see that this is very easy and straightforward to use this Marshall operation.

36
00:02:27,130 --> 00:02:34,840
We don't specify any end or s character for string and number data types of dynamo dynamo DB Key Attributes.

37
00:02:34,930 --> 00:02:40,900
Okay, if you come here and collect the control space, you can see that it is using a k util dynamo.

38
00:02:40,900 --> 00:02:48,940
DB Please import this library and verify that this importing marshall library from the Dynamo ADB and

39
00:02:48,940 --> 00:02:50,320
we have also on Marshall.

40
00:02:50,350 --> 00:02:54,460
That means we are using a marshall for return back to JSON object.

41
00:02:54,460 --> 00:03:01,300
So please add our Marshall also and make sure that you have import this statement successfully.

42
00:03:01,450 --> 00:03:07,040
And after that, if you scroll down you can see that we are using Dynamo DB Client Object Edge.

43
00:03:07,120 --> 00:03:10,900
Remember that we have already create the DB client object in the previous section.

44
00:03:10,900 --> 00:03:15,190
So come here, click the control space and import these object.

45
00:03:15,700 --> 00:03:16,840
No, not this one.

46
00:03:16,840 --> 00:03:18,130
Let me come here.

47
00:03:19,890 --> 00:03:20,460
Okay.

48
00:03:20,460 --> 00:03:25,290
We should use the DB client object as a export statement.

49
00:03:25,290 --> 00:03:27,630
I'm going to write by manually.

50
00:03:27,720 --> 00:03:37,110
To do so, let me come here and paste this import statement and make sure that you have added that JS

51
00:03:37,110 --> 00:03:45,380
file and see that we can now reach the dynamic DB client object from our exporting dynamo.

52
00:03:45,390 --> 00:03:48,650
DB Client Node.js Separate Node.js module.

53
00:03:48,660 --> 00:03:52,200
So now let's continue to our import statement, open index.

54
00:03:52,200 --> 00:03:58,740
JS So we have import dynamo DB Client object and make sure and verify that you have import successfully

55
00:03:58,890 --> 00:04:00,600
at the right JavaScript file.

56
00:04:00,600 --> 00:04:03,420
And please don't forget it JavaScript file.

57
00:04:03,660 --> 00:04:08,010
And after that there is a new parameter which is creating new command.

58
00:04:08,010 --> 00:04:11,760
So that's why we should add this command into our import statement.

59
00:04:11,760 --> 00:04:15,750
Come here and click control space and add required command.

60
00:04:16,350 --> 00:04:20,700
Somehow it is not working for me, not adding import statement automatically.

61
00:04:20,730 --> 00:04:25,530
It is showing the right package, but not importing automatically for that purpose.

62
00:04:25,530 --> 00:04:28,110
I'm going to add import statement manually.

63
00:04:28,140 --> 00:04:33,060
If you come here and put this import statement, this is very important.

64
00:04:33,090 --> 00:04:38,760
Make sure that you have import gate item command from the client dynamic DB SDK package.

65
00:04:38,790 --> 00:04:44,880
And if you scroll down, you can see the color of the gate item command is become green, so that means

66
00:04:44,880 --> 00:04:46,980
it is important successfully.

67
00:04:47,430 --> 00:04:53,640
Okay, so let me come here and show the whole method and explain from the secret.

68
00:04:54,120 --> 00:04:56,720
So basically we start with logging.

69
00:04:56,730 --> 00:05:01,830
This is very important because we won't debug any code when developing serverless applications.

70
00:05:01,830 --> 00:05:05,100
So we will check our code from a cloud which logs.

71
00:05:05,100 --> 00:05:08,130
That's why it is important to put logs efficiently.

72
00:05:08,130 --> 00:05:10,470
So that's why we get product log.

73
00:05:10,500 --> 00:05:17,070
That means we will come into this method is the same way if we interact or connect other resources it

74
00:05:17,070 --> 00:05:23,490
is good to cover try cage block in order to follow errors in the cloud watch logs.

75
00:05:23,490 --> 00:05:30,840
So after the log we have covered with the cage block and after that we have full load dynamic DB SDK

76
00:05:30,840 --> 00:05:34,620
documentation and create parameters for the gate item command.

77
00:05:34,670 --> 00:05:36,810
You can see the parameters in here.

78
00:05:36,840 --> 00:05:42,270
Basically, you can think dynamic DB is a service and expose some APIs to us for performing current

79
00:05:42,270 --> 00:05:43,860
operations on database.

80
00:05:43,860 --> 00:05:46,800
And these APIs requires some parameters.

81
00:05:46,800 --> 00:05:53,850
So in our case, we use Git item command dynamic DB API and it requires parameters which including the

82
00:05:53,880 --> 00:05:56,550
table name and the K, which is the primary key.

83
00:05:56,550 --> 00:05:59,160
And in our case it is only partition key.

84
00:05:59,640 --> 00:06:04,410
So if we don't send these parameters, our API will not return success response.

85
00:06:05,770 --> 00:06:08,970
We can check the detail of the gate item command in the SSC class.

86
00:06:08,980 --> 00:06:11,770
If you come here right click and go to definition.

87
00:06:11,890 --> 00:06:15,120
You can see the actual implementation code in here.

88
00:06:15,130 --> 00:06:21,910
So basically, for example, go to get item command input to see parameters.

89
00:06:21,910 --> 00:06:29,650
And if you scroll down and go to get item input, you can see that these are the input parameters that

90
00:06:29,650 --> 00:06:32,560
we should define when we interact with the gate item command.

91
00:06:32,590 --> 00:06:38,710
Here you can see table name key attributes to get consistent need and so on.

92
00:06:38,860 --> 00:06:42,640
As you can see that these two attributes are knowable.

93
00:06:42,640 --> 00:06:45,460
So that means we don't have to set these parameters.

94
00:06:45,460 --> 00:06:51,790
These are the normal parameters and these key and the table name is a monetary, you can see quotation

95
00:06:51,790 --> 00:06:52,120
marks.

96
00:06:52,120 --> 00:06:57,790
So that means these are the mandatory attributes that we should provide when we are using the get item

97
00:06:57,790 --> 00:06:58,360
command.

98
00:06:58,390 --> 00:07:06,580
If you come back to our code, which is the index case, so we can see that we will use get item command

99
00:07:06,580 --> 00:07:09,970
and we have import required get item command statements.

100
00:07:09,970 --> 00:07:17,950
And after that we use this dynamo DB client that said operation and this is async anonymous function

101
00:07:17,950 --> 00:07:23,950
that we send request to the dynamic DB client object and sending get item command as we explained version

102
00:07:23,950 --> 00:07:32,290
three of the JavaScript HDC and these await operation basically return the item into the dynamic DB

103
00:07:32,290 --> 00:07:32,890
table.

104
00:07:33,190 --> 00:07:34,330
This is the item object.

105
00:07:34,330 --> 00:07:42,430
Return back to Dynamo DB table and we basically console look this operation and return back this item

106
00:07:42,430 --> 00:07:44,050
with our Marshall operation.

107
00:07:44,050 --> 00:07:50,350
So that means we are converting as a JSON format and we look the response and return back to method.

108
00:07:50,350 --> 00:07:56,080
So as you can see that we have developed great product method for retrieving a single product item into

109
00:07:56,080 --> 00:07:57,730
Dynamo DB database.

110
00:07:57,730 --> 00:07:59,830
So let's start implement other methods.
