1
00:00:00,150 --> 00:00:06,600
In this video, we are going to continue the development of order, acknowledgment microservices and

2
00:00:06,600 --> 00:00:10,210
in the last video we have left the third and the first step.

3
00:00:10,230 --> 00:00:15,630
If you go to the our indexes, you can see that we are going to develop these two steps.

4
00:00:15,630 --> 00:00:20,250
And now I'm going to focus on the third step, which is the published message to topic on Amazon.

5
00:00:20,280 --> 00:00:22,560
Since using the SDK libraries.

6
00:00:22,620 --> 00:00:26,630
So before we start, it is good to check the documentation.

7
00:00:26,640 --> 00:00:32,110
If you open the source client documentation, this is the library for a SDK.

8
00:00:32,130 --> 00:00:37,620
You can see that we will use publish command and if you open the publish command, you can see all the.

9
00:00:38,430 --> 00:00:45,200
Basically it is send a message to Amazon sans topic and we will use these publish command in our example.

10
00:00:45,210 --> 00:00:51,450
If we send a message to Amazon says topic, Amazon says delivers the message to each end point that

11
00:00:51,450 --> 00:00:52,920
is subscribed to the topic.

12
00:00:52,920 --> 00:00:57,290
And the format of the message depends on the notification protocol for each subscribe.

13
00:00:57,310 --> 00:01:02,250
And in our case our subscriber systems are case.

14
00:01:02,250 --> 00:01:07,350
So we will use a SCS protocol for subscription to Amazon sans topic.

15
00:01:07,810 --> 00:01:08,120
Okay.

16
00:01:08,130 --> 00:01:10,940
If you come back to the documentation, you can see the publish command.

17
00:01:10,950 --> 00:01:16,770
If you scroll down here, you can see the example usage and you can check the input and outputs from

18
00:01:16,770 --> 00:01:18,760
the objects of the published command input.

19
00:01:18,780 --> 00:01:24,720
Here you can see that we will provide these information publishing an item into the sense topic and

20
00:01:24,720 --> 00:01:26,760
also you can see the publish command output.

21
00:01:26,790 --> 00:01:30,210
This will return us to message ID and sequence number.

22
00:01:30,540 --> 00:01:32,200
Okay, let's get started.

23
00:01:32,220 --> 00:01:35,370
The first thing we should create the client object.

24
00:01:35,370 --> 00:01:37,620
So when it comes to work, any sense?

25
00:01:37,620 --> 00:01:38,130
Object.

26
00:01:38,130 --> 00:01:38,870
Client object.

27
00:01:38,880 --> 00:01:44,730
First thing we should do is create separate client Node.js module in order to interact with sense client

28
00:01:44,730 --> 00:01:45,330
object.

29
00:01:45,360 --> 00:01:50,820
To do that, I'm going to open the command text and I have listed what we have done, what we are going

30
00:01:50,820 --> 00:01:51,150
to do.

31
00:01:51,150 --> 00:01:57,870
In this video, we basically examine the source client documentation and now I'm going to create a sense

32
00:01:57,870 --> 00:02:01,750
client JS file and implement this Node.js function.

33
00:02:01,770 --> 00:02:07,170
If you create a sense client JS and implement this code, this will be provided to interact with this

34
00:02:07,200 --> 00:02:07,530
client.

35
00:02:07,530 --> 00:02:14,190
We have done these methods before when we interacting the source SDK operations and after that now we

36
00:02:14,190 --> 00:02:16,160
can implement our actual logic.

37
00:02:16,170 --> 00:02:23,460
But before implementing the actual logic, it is best practice to use a lambda environment variables.

38
00:02:23,460 --> 00:02:29,460
So before start coding, it is good to create a source topic run as an environment variable for order

39
00:02:29,470 --> 00:02:35,790
acknowledge lambda function because we will use the aaron of the topic in the development of to publish

40
00:02:35,790 --> 00:02:40,830
message when we are providing the request parameters of the publish command.

41
00:02:40,830 --> 00:02:49,440
So for that purpose I'm going to open the or a console and first of all go to this topic and get the

42
00:02:49,440 --> 00:02:51,680
Aaron over to our order topic.

43
00:02:51,690 --> 00:02:56,160
If you come here, go to topics and open the order topic, you can copy this.

44
00:02:56,160 --> 00:03:03,900
Aaron And after that, go create, go to lambda of the management console and open the order acknowledgement

45
00:03:03,900 --> 00:03:06,870
lambda function and go to configuration.

46
00:03:06,990 --> 00:03:13,500
And if you go to environment variables, I'm going to create an environment variable at any one table

47
00:03:13,590 --> 00:03:16,380
which the value should be the or order topic.

48
00:03:16,390 --> 00:03:20,310
Aaron And the environment key will be topic.

49
00:03:20,340 --> 00:03:26,010
Aaron Please give and provide this environment variable copy from the order topic.

50
00:03:26,010 --> 00:03:28,290
Aaron And paste in the key of the topic.

51
00:03:28,290 --> 00:03:30,240
Aaron And click this button.

52
00:03:31,230 --> 00:03:34,740
So we will use this environment variable into our application.

53
00:03:35,010 --> 00:03:37,380
As you remember that this is the best practice.

54
00:03:37,410 --> 00:03:40,860
Get these names from the environment variables into lambda function.

55
00:03:40,860 --> 00:03:47,250
By this way, we don't change any Aaron if we are since provider is changed we only change the value

56
00:03:47,250 --> 00:03:47,610
in here.

57
00:03:47,610 --> 00:03:50,310
Don't change the lambda actual function code.

58
00:03:50,340 --> 00:03:56,550
If you open the our actual code now we can publish message to the sense in our lambda function code.

59
00:03:56,550 --> 00:03:58,830
So basically the idea is the same.

60
00:03:58,830 --> 00:04:01,020
We will prepare for the parameters.

61
00:04:01,020 --> 00:04:02,790
So I'm going to create a parameters.

62
00:04:02,790 --> 00:04:08,400
First, in the parameters, we are providing the message as a order request that we are prepared in

63
00:04:08,400 --> 00:04:12,000
the first two steps and after that we are pacing the topic.

64
00:04:12,000 --> 00:04:18,780
Aaron See that we are getting topic Aaron from process start and we the topic Aaron that we provide

65
00:04:18,780 --> 00:04:20,940
in the last couple of minutes.

66
00:04:20,940 --> 00:04:26,430
So after that we pass these parameters to the publish command.

67
00:04:26,430 --> 00:04:29,880
So in order to do that, I'm going to import record statement.

68
00:04:29,880 --> 00:04:36,240
So this is very important to add a required import statement, go on top of the page, and after that

69
00:04:36,240 --> 00:04:43,200
we will import the required package with importing publish command from the SNS client and also import

70
00:04:43,860 --> 00:04:44,580
source client.

71
00:04:44,760 --> 00:04:49,410
JS Separate module object to send required commands in our application.

72
00:04:49,410 --> 00:04:55,020
So after import these two statements, if you scroll down, you can see that our published command makes

73
00:04:55,020 --> 00:04:59,190
green and now we can send these publish command with using these parameters.

74
00:04:59,190 --> 00:04:59,730
And one of the.

75
00:05:00,060 --> 00:05:02,420
This comes from the lambda environment for us.

76
00:05:02,650 --> 00:05:03,140
Okay.

77
00:05:03,180 --> 00:05:09,150
That means we have successfully performed the third step, which is the published message to SNS and

78
00:05:09,150 --> 00:05:13,710
we are log the operation which is incoming from the published command data.

79
00:05:14,020 --> 00:05:14,780
Okay, very good.

80
00:05:14,790 --> 00:05:20,190
Now it is time to develop the fourth step in order to perform the fourth step, which is the save order

81
00:05:20,190 --> 00:05:21,570
item in dynamic DB.

82
00:05:21,600 --> 00:05:25,110
I have created on the command text file and several documentation.

83
00:05:25,110 --> 00:05:26,650
We will follow the same steps.

84
00:05:26,670 --> 00:05:28,980
First of all, we will check the documentation.

85
00:05:29,190 --> 00:05:35,580
We have already know that dynamo DB client documentation from a SDK, but this time we will use put

86
00:05:35,580 --> 00:05:36,270
item command.

87
00:05:36,270 --> 00:05:38,130
You can check the put item command.

88
00:05:38,130 --> 00:05:43,230
This will be basically insert an item on Dynamo TV and here you can see the input and output.

89
00:05:43,230 --> 00:05:49,560
When we are inserting any words from Dynamo DB, we will use also util dynamo DB library to make it

90
00:05:49,560 --> 00:05:49,980
simple.

91
00:05:49,980 --> 00:05:53,400
And these are the input parameters and these are the output parameters.

92
00:05:53,740 --> 00:05:59,580
OC After that, if you come back to our documentation, basically we will create the Dynamo DB Klein.

93
00:05:59,790 --> 00:06:03,720
JS This we will separate the Dynamo DB Client Node.js module.

94
00:06:03,750 --> 00:06:08,820
If you open the DB client JS, please create this file and implement this code.

95
00:06:08,850 --> 00:06:13,560
Have already know that this could provide to interact with Dynamo DB and if you come back the other

96
00:06:13,560 --> 00:06:16,710
items, the other item is set to environment variables.

97
00:06:16,800 --> 00:06:22,680
Again, I am going to open a maven console and go to configuration environment variables and I'm going

98
00:06:22,680 --> 00:06:28,230
to add new environment variable for the dynamo db table name is note that we will create an order table

99
00:06:28,230 --> 00:06:30,720
and I would like to get the table name from the environment.

100
00:06:30,720 --> 00:06:34,640
Variables of the order acknowledgements lambda function and click this Ableton.

101
00:06:35,190 --> 00:06:36,000
Okay, very good.

102
00:06:36,000 --> 00:06:42,090
We have now to my tables and now I'm ready to implement our Save Dynamo DB operation.

103
00:06:42,090 --> 00:06:48,780
If you come back to our index case and go to the save order item in Dynamo DB path and now we will follow

104
00:06:48,780 --> 00:06:49,830
the same steps.

105
00:06:49,830 --> 00:06:56,410
Basically this time we will use put item command and Marshall and Marshall operations from the util

106
00:06:56,430 --> 00:07:00,660
dynamo DB and I will use the Dynamo DB clients to do that.

107
00:07:00,660 --> 00:07:06,480
I would like to start with the adding to import segment because it is very important to adding record

108
00:07:06,480 --> 00:07:07,650
import statements.

109
00:07:07,650 --> 00:07:14,340
So please add the correct import statement as well as like me, you can see that we are adding to put

110
00:07:14,340 --> 00:07:20,640
item command in Dynamo DB client object and also we are using Marshall and Marshall from Util Library.

111
00:07:20,640 --> 00:07:25,670
And lastly, I have added to Dynamo DB client from our separate Node.js module to interact with Dynamo

112
00:07:25,680 --> 00:07:27,120
DB OC.

113
00:07:27,480 --> 00:07:32,940
After that, after importing these statements now we will develop our actual operation.

114
00:07:32,940 --> 00:07:39,570
So for that purpose I have prepared a dynamo DB parameters and after that paste these parameters into

115
00:07:39,570 --> 00:07:41,250
our client object.

116
00:07:41,250 --> 00:07:47,520
So you can see in this line of code we will provide this line of code in action for the for this action.

117
00:07:47,580 --> 00:07:50,550
Basically here you can find the dynamic DB parameters.

118
00:07:50,550 --> 00:07:56,040
Placing the table name and table name comes from the environment variables and placing the item.

119
00:07:56,040 --> 00:07:59,160
So if you check the item, this is the order request.

120
00:07:59,160 --> 00:08:02,670
So we will prepare the order request from the incoming event.

121
00:08:02,670 --> 00:08:09,950
But that's why we will validate and that's why we will set the ID as a UID because ID is the order partition

122
00:08:09,960 --> 00:08:14,310
key and we have to provide these ID information, otherwise it will get exception.

123
00:08:14,310 --> 00:08:20,430
So by this way, we can pass the whole order request as the item of the Dynamo DB table.

124
00:08:20,460 --> 00:08:23,760
Of course, using the Marshall Utility Library.

125
00:08:23,940 --> 00:08:24,350
Okay.

126
00:08:24,360 --> 00:08:28,380
After preparing the Dynamo DB parameters, the others are very similar.

127
00:08:28,380 --> 00:08:34,830
We are using the put item command to insert any item and sending with using the dynamic DB client object.

128
00:08:34,830 --> 00:08:38,510
And we got the create result and we are logging that successfully.

129
00:08:38,550 --> 00:08:42,060
Create an item on Dynamo DB OC.

130
00:08:42,090 --> 00:08:51,300
As you can see that we have successfully publish topic on Amazon SAS using a SDK libraries and after

131
00:08:51,300 --> 00:08:54,930
that we will save item on Dynamo DB order table.

132
00:08:54,930 --> 00:08:57,690
So we will finish the development of the order.

133
00:08:57,690 --> 00:09:00,750
Acknowledgements with interacting sense and Dynamo.

134
00:09:00,750 --> 00:09:01,410
DB Table.
