1
00:00:00,180 --> 00:00:07,290
In this video, we are going to develop dynamic DB query and scan operations for our product Lambda

2
00:00:07,290 --> 00:00:10,920
Microservices using Dynamic DB Client SDK package.

3
00:00:11,370 --> 00:00:16,500
Before we start, it is good to remember you can create operations on Dynamic DB.

4
00:00:16,710 --> 00:00:19,470
To do so, please check the documentation.

5
00:00:19,470 --> 00:00:21,840
See that scan operation in Amazon?

6
00:00:21,840 --> 00:00:28,750
Dynamic DB reads every item in a table, so that means it is very costly and we should await these dynamic

7
00:00:28,750 --> 00:00:31,300
DB scan operations as soon as possible.

8
00:00:31,320 --> 00:00:38,010
And here you can see the an example CLI command that we can also provide these slide command operations.

9
00:00:38,010 --> 00:00:40,320
So you can comment on dynamic DB.

10
00:00:40,350 --> 00:00:46,350
Here you can see the table name and we can also give additional feature expression over the table name.

11
00:00:46,350 --> 00:00:52,200
But nevertheless, you can command, always overview and read every item in the table.

12
00:00:52,200 --> 00:00:54,630
So that's why it is a bit dangerous.

13
00:00:54,630 --> 00:00:59,160
And we have also created a command to perform query operations Dynamo DB.

14
00:00:59,190 --> 00:01:01,920
It is the best practice to use query command.

15
00:01:01,950 --> 00:01:05,400
Here you can see the Dynamo DB Query Select Command.

16
00:01:05,430 --> 00:01:12,270
Again, we also provide a table name, but this time we can provide key condition, expression and expression

17
00:01:12,270 --> 00:01:14,940
attribute values for the other attributes.

18
00:01:15,240 --> 00:01:23,190
OC After understand the basics, we can go back to our code and we can see how we can implement these

19
00:01:23,190 --> 00:01:24,480
query operation.

20
00:01:24,660 --> 00:01:29,650
As you remember that we have already implemented scan operation into the get all products.

21
00:01:29,670 --> 00:01:36,510
If you go to this method, see that we perform scan command with placing these parameters, the only

22
00:01:36,510 --> 00:01:37,710
parameter is a table name.

23
00:01:37,710 --> 00:01:43,140
So that means it is reading all items in the table name and it is a bit costly.

24
00:01:43,290 --> 00:01:50,940
So if you go back to our main function and the function, so here you can see the HTTP get operations

25
00:01:50,940 --> 00:01:56,190
accommodate in this line of code we basically perform check the parameters.

26
00:01:56,190 --> 00:01:59,700
If there is a parameters, we are using the get item command.

27
00:01:59,730 --> 00:02:06,180
If there is no parameters, we are getting all products on the DB table with using scan command.

28
00:02:06,310 --> 00:02:10,530
Now I'm going to add a new HTTP get request.

29
00:02:10,560 --> 00:02:18,670
Let me show in here so you can see the expected HTTP, get request to our product Lambda Microservice

30
00:02:18,720 --> 00:02:19,440
function.

31
00:02:19,530 --> 00:02:23,820
So now this code is accommodate these two requests.

32
00:02:23,820 --> 00:02:29,820
The first one is the parameters we checking the ID information gate product by ID and the second one

33
00:02:29,820 --> 00:02:33,150
is the gate all products with performing the scan command.

34
00:02:33,150 --> 00:02:41,490
So now I'm going to expect any HTP gate method with providing both parameters and also query setting

35
00:02:41,490 --> 00:02:42,450
parameters.

36
00:02:42,450 --> 00:02:50,130
So how we can accommodate this request in this line of code, of course, we should write any if statement

37
00:02:50,130 --> 00:02:51,540
into the gate.

38
00:02:51,540 --> 00:02:58,620
BLOCK So for that purpose, I'm going to write an E flow and after that I can change the below if log

39
00:02:58,620 --> 00:02:59,410
is LC.

40
00:03:00,840 --> 00:03:03,680
Here you can see the our development codes.

41
00:03:03,690 --> 00:03:09,480
Basically, we have checking to create setting parameters and if there is a query setting parameters

42
00:03:09,480 --> 00:03:12,760
so that means it should be get products by category.

43
00:03:12,780 --> 00:03:17,180
With passing event, we are performing to get products by category.

44
00:03:17,190 --> 00:03:20,610
And in this method we will perform query command operations.

45
00:03:20,610 --> 00:03:29,580
So as you can see that we basically accommodate all these requests from more specific one to less specific

46
00:03:29,580 --> 00:03:30,060
one.

47
00:03:30,060 --> 00:03:35,970
So the code structure looking for the query setting parameter if there is a query in parameter, so

48
00:03:35,970 --> 00:03:38,370
that means get product by category.

49
00:03:38,430 --> 00:03:45,420
If there is no category in the query setting parameter, we are checking the parameters and that means

50
00:03:45,420 --> 00:03:49,230
it is a get product by ID if there is no parameters.

51
00:03:49,230 --> 00:03:54,570
So in that case, this is to get all products and to perform second command.

52
00:03:54,570 --> 00:04:00,330
So let's focus on this line of code and how we can implement these methods before we start.

53
00:04:00,330 --> 00:04:02,610
It is good to check the documentation.

54
00:04:02,610 --> 00:04:09,030
Please open the dynamic DB SDK documentation and open the query command and see that how we can perform

55
00:04:09,030 --> 00:04:10,830
query command and see the example.

56
00:04:10,830 --> 00:04:12,000
Use it in here.

57
00:04:12,000 --> 00:04:18,450
And if you go to query command input object, we will see the parameters that we can define when performing

58
00:04:18,460 --> 00:04:20,700
to query command on dynamic DB tables.

59
00:04:21,030 --> 00:04:24,000
Okay, let's go back to our we to do code.

60
00:04:24,000 --> 00:04:29,190
And if you go to get all products, you can see the second command example in here.

61
00:04:29,220 --> 00:04:36,030
After the these get all products, I'm going to develop a method which name is get products by category.

62
00:04:36,150 --> 00:04:44,400
If you can see in here, we basically will get products by category with this this line of codes.

63
00:04:44,400 --> 00:04:48,030
So first of all, I'm going to import record statements.

64
00:04:48,030 --> 00:04:51,870
Let me see what we are going to import.

65
00:04:51,870 --> 00:04:59,640
So the DB client and new query command, see that query command should be import or dynamic DB client

66
00:04:59,640 --> 00:05:00,660
SDK package.

67
00:05:00,690 --> 00:05:04,230
Go on top of the page and come here after the update command.

68
00:05:04,230 --> 00:05:10,080
I'm going to put comma and write query command into the client dynamic DB SDK package.

69
00:05:10,110 --> 00:05:17,160
If you go back to our main method, which is get product by category, you can come here and see that

70
00:05:17,160 --> 00:05:21,540
this time we can use Query Command OC before we start explaining.

71
00:05:21,540 --> 00:05:28,890
We should understand which HTTP method and which URL will be accommodated in this line of methods.

72
00:05:28,890 --> 00:05:31,920
So basically we will accommodate this request.

73
00:05:31,920 --> 00:05:38,280
So that means we will start with logging and after the track block, the first thing we should do is

74
00:05:38,310 --> 00:05:44,790
getting product ID and category information from the pet parameters and the query setting parameters.

75
00:05:44,790 --> 00:05:45,930
This is important.

76
00:05:45,930 --> 00:05:50,310
For example, we are getting queries, setting parameters category, so that means it is return back

77
00:05:50,310 --> 00:05:52,560
to form in the category variable.

78
00:05:52,560 --> 00:05:58,470
And after that we get the pet parameters ID information into the product ID variable.

79
00:05:58,560 --> 00:06:04,860
After getting these two variables, we can prepare the parameters of the query command and in the parameters

80
00:06:04,860 --> 00:06:10,260
we provide the key condition, expression, filter, expression and expression, attribute, values

81
00:06:10,260 --> 00:06:11,220
and the table name.

82
00:06:11,220 --> 00:06:19,050
So these is the query command parameters that we are defining the product ID and also category information

83
00:06:19,050 --> 00:06:23,340
to query our table looking for the category information.

84
00:06:23,370 --> 00:06:30,120
After that, we will send a dynamic client object to create a command and get back to await response

85
00:06:30,120 --> 00:06:35,520
into the item result to get these all items and return back to items into our function.

86
00:06:35,520 --> 00:06:40,530
So this is the get products by category method that we will implement this file.

87
00:06:40,560 --> 00:06:42,870
Please save the index case file.

88
00:06:42,930 --> 00:06:50,760
And as you can see that we have successfully developed the whole product microservices for performing

89
00:06:50,760 --> 00:06:56,490
CRUD operation over the dynamic DB table and response back to API gateway to the client application.
