1
00:00:00,210 --> 00:00:06,750
In this video, we are going to continue to create our infrastructure for public subscription architecture

2
00:00:06,750 --> 00:00:09,390
with using SAS case and Lambda.

3
00:00:09,780 --> 00:00:16,050
As you remember that we have left only one service, which is the Amazon sions that we will create during

4
00:00:16,050 --> 00:00:16,690
this video.

5
00:00:16,710 --> 00:00:19,830
So let's create Amazon SAS and topic.

6
00:00:19,860 --> 00:00:25,620
Please open the console, go to SAS and topics and click the create topic.

7
00:00:25,740 --> 00:00:30,440
So we will select the type of the topic as a standard, not FIFO.

8
00:00:30,480 --> 00:00:33,720
Please select this on that and give the topic name as an order topic.

9
00:00:33,990 --> 00:00:39,810
And if you scroll down, I'm not going to change any configuration and go to the create topic button

10
00:00:39,810 --> 00:00:40,950
and click this button.

11
00:00:41,680 --> 00:00:49,090
So as you can see that we had success to create order topic and now it is time to subscribe this topic

12
00:00:49,090 --> 00:00:50,730
from the sky schools.

13
00:00:50,740 --> 00:00:58,570
So if you go back to our architecture and see that we have three Qs that will subscribe to Amazon sans

14
00:00:58,600 --> 00:01:05,920
topic and this will be subscribed from the Qs one for the notification queue, inventory queue and shipment

15
00:01:05,920 --> 00:01:06,490
queue.

16
00:01:06,520 --> 00:01:14,650
All these three Qs will be subscribed to Amazon topic and get the message from the SMS topic and this

17
00:01:14,650 --> 00:01:18,520
message will be consumed and pull from the downstream microservices.

18
00:01:18,520 --> 00:01:26,740
So now we should create subscriptions from Amazon to SNS to provide the message delivery for that purpose.

19
00:01:26,740 --> 00:01:32,380
Please open the console, go to the order topic and if you scroll down you can see the subscriptions

20
00:01:32,380 --> 00:01:34,330
and we don't have any subscription.

21
00:01:34,390 --> 00:01:41,650
But according to our architecture, these three SKUs should be subscription of our SNS topic.

22
00:01:41,650 --> 00:01:45,910
For that, we will click the create subscription button and select the protocol.

23
00:01:46,030 --> 00:01:51,670
In our protocol will be Amazon SP Q and the endpoints will be all these three.

24
00:01:51,670 --> 00:01:58,810
Q So I'm going to select one by one and I'm going to create subscription, but you can check the subscription

25
00:01:58,810 --> 00:02:01,360
filter policy and drive policy.

26
00:02:01,360 --> 00:02:02,890
We don't set any configuration.

27
00:02:02,890 --> 00:02:09,910
We only set the protocol case and we will give the endpoint as a inventory cue and we will create subscription.

28
00:02:10,540 --> 00:02:13,660
And as you can see that the subscription creates successfully.

29
00:02:13,660 --> 00:02:20,080
If you come back to order topic, we can see the subscription list has one item now, but I follow the

30
00:02:20,080 --> 00:02:21,850
same step for the other Q's.

31
00:02:21,880 --> 00:02:28,060
Click to create subscription, select the SKU and this will be notification.

32
00:02:28,060 --> 00:02:33,550
Q So scroll down and click the subscription and go back to the topics again.

33
00:02:33,550 --> 00:02:40,870
Order topic, scroll down, go to subscription, create subscription, select the case and end point

34
00:02:40,870 --> 00:02:44,590
will be shipment Q, scroll down and create subscription.

35
00:02:45,310 --> 00:02:52,000
If you come back to order topic and scroll on, you can see the subscription systems are three SKUs

36
00:02:52,000 --> 00:02:55,060
which are the inventory notification and shipment.

37
00:02:55,060 --> 00:03:01,360
So that means these SKUs successfully subscribe to our order sense topic.

38
00:03:01,420 --> 00:03:10,210
But it is not enough because in order to publish message to the Amazon excuse after provide to subscriptions,

39
00:03:10,210 --> 00:03:13,270
it is also required to giving permissions.

40
00:03:13,270 --> 00:03:19,180
So that means we should give required permissions to Amazon sans topic in order to send message to the

41
00:03:19,180 --> 00:03:20,680
Amazon SKU.

42
00:03:21,070 --> 00:03:26,200
For that purpose, Amazon says topic should be able to send message to the Q.

43
00:03:26,230 --> 00:03:33,640
We have to set a policy on the Q that allows the Amazon topic to perform as send message action.

44
00:03:33,640 --> 00:03:40,330
So that means we should give required permission, which is the send message permission into the our

45
00:03:40,540 --> 00:03:43,240
case, which will be triggered from the Psns.

46
00:03:43,240 --> 00:03:51,580
So in order to do that, I'm going to go to the old cues one by one, and I'm going to set the principle

47
00:03:51,580 --> 00:03:53,290
to Amazon services.

48
00:03:53,290 --> 00:04:02,590
So let's go back to our advertisement console and open the excuse and we will open one by one and edit

49
00:04:02,590 --> 00:04:08,620
the access policy of these Qs to provide to accommodate incoming message from the PSNS.

50
00:04:08,650 --> 00:04:14,200
Let me start with immature Q Please open the queue and if you open the queue you can see that we have

51
00:04:14,200 --> 00:04:15,760
access policy settings.

52
00:04:15,760 --> 00:04:21,070
If you come here, you can see that this is the default settings that is provided to principal from

53
00:04:21,070 --> 00:04:22,510
the root directory.

54
00:04:22,510 --> 00:04:30,520
But we need to set and change these access policy in order to send message from the Amazon SNS.

55
00:04:30,760 --> 00:04:35,470
To do that, we have to set the principal as the Amazon service.

56
00:04:35,470 --> 00:04:41,830
You can come here and you can change these principal, as Amazon says, in order to do that, I'm I

57
00:04:41,830 --> 00:04:47,560
have created separate lecture and section folder into our widget pseudocode.

58
00:04:47,590 --> 00:04:53,320
You can see here we are in this step we have created the Amazon sans topic, which is the order topic.

59
00:04:53,320 --> 00:05:00,700
After that we have subscribed from the old excuse and now it is time to set principal to be Amazon service.

60
00:05:00,700 --> 00:05:07,000
So I'm going to open one by one old school SKU and change the principal value as a service which is

61
00:05:07,000 --> 00:05:10,030
the start of Amazon dot com.

62
00:05:10,180 --> 00:05:16,270
So if you come back to our console, I'm going to change this line of code page, click the edit button.

63
00:05:17,390 --> 00:05:22,850
If you scroll down and come to here, we basically change only this principle service.

64
00:05:22,850 --> 00:05:27,200
So I'm going to change this principle, add this to the service.

65
00:05:27,200 --> 00:05:34,490
So that means we are giving an allowing the service of the SNS to publish message to a space.

66
00:05:34,490 --> 00:05:42,980
That means we are giving all actions about the space, but we are particularly interested with the send

67
00:05:42,980 --> 00:05:43,910
message action.

68
00:05:44,270 --> 00:05:49,610
Okay, so after change this principle, scroll down and click the save button.

69
00:05:50,630 --> 00:05:56,270
We have successfully changed access policy for the eventual Q and please follow the same step for the

70
00:05:56,270 --> 00:05:56,930
other Qs.

71
00:05:56,930 --> 00:06:02,990
Go back to Qs, open the notification service, come to access policy, edit policy, scroll on.

72
00:06:03,110 --> 00:06:06,650
Change this line of code from a service of SAS.

73
00:06:06,650 --> 00:06:08,540
So scroll down and click the save.

74
00:06:08,960 --> 00:06:12,140
Okay, I'm going to follow this same step with the shipment.

75
00:06:12,440 --> 00:06:18,080
Go accessibility, click the edit button, scroll down, change this line of code, scroll down and

76
00:06:18,080 --> 00:06:19,100
click this button.

77
00:06:19,670 --> 00:06:21,140
Okay, very good.

78
00:06:21,140 --> 00:06:26,870
So that means we have successfully give required permission and we are now ready for the publish message

79
00:06:26,870 --> 00:06:28,520
from the Amazon Sans.

80
00:06:28,520 --> 00:06:35,960
And this will be subscribe from the TV HQ HQ and this will be consumed from these downstream microservices.

81
00:06:35,960 --> 00:06:39,440
So now it is time to test publishing sense message.

82
00:06:39,440 --> 00:06:40,400
For that purpose.

83
00:06:40,430 --> 00:06:47,690
Please go to the main console, go to Amazon source topics and open the order topic and click the publish

84
00:06:47,690 --> 00:06:48,350
message.

85
00:06:48,350 --> 00:06:53,440
So I'm going to send the message which is the subject as an order placed.

86
00:06:53,480 --> 00:06:54,710
This is our use case.

87
00:06:54,710 --> 00:06:58,580
And if you scroll down here, you can see the our message body.

88
00:06:58,580 --> 00:07:00,560
So I'm going to put a JSON.

89
00:07:01,300 --> 00:07:07,810
But the information which is basically order place JSON, this is the item status and the type including

90
00:07:07,810 --> 00:07:10,940
this JSON, you can increase the attributes.

91
00:07:10,960 --> 00:07:15,100
If you scroll down, I'm going to publish the message, click the publish message.

92
00:07:15,100 --> 00:07:22,450
So a message published successfully that means this message is published from the Amazon since unsubscribe

93
00:07:22,450 --> 00:07:29,590
from the excuse and these queues are consumed by the pool by the distance to microservices, that means

94
00:07:29,590 --> 00:07:36,880
if I go and go to the notification microservices and go to cloud which looks I should see that the invocation

95
00:07:36,880 --> 00:07:40,480
happens from the SAS s case and the lambda function.

96
00:07:40,480 --> 00:07:44,200
Let's go to the lambda function and see the invocation comes or not.

97
00:07:44,410 --> 00:07:46,390
Go to Lambda Page.

98
00:07:47,300 --> 00:07:48,240
Go to functions.

99
00:07:48,260 --> 00:07:50,180
Open the notification microservices.

100
00:07:50,210 --> 00:07:53,330
Go to monitor and weave in cloud watch logs.

101
00:07:53,720 --> 00:07:56,840
So if you open the latest log in cloud which.

102
00:07:58,870 --> 00:08:00,040
We should see the invocation.

103
00:08:00,040 --> 00:08:01,930
Yes, the invocation comes in here.

104
00:08:02,730 --> 00:08:02,910
Here.

105
00:08:02,910 --> 00:08:08,820
You can see the invocation comes successfully in order to see the incoming event JSON object, we should

106
00:08:08,820 --> 00:08:11,040
log the incoming event for that purpose.

107
00:08:11,040 --> 00:08:18,000
I'm going to change the lambda function code so we should look the incoming event for all our lambda

108
00:08:18,000 --> 00:08:18,480
function.

109
00:08:18,480 --> 00:08:25,080
I have put one more step which is the adding console log line of code into all lambda functions.

110
00:08:25,110 --> 00:08:31,080
Go to lambda functions and please add all log operations into all functions.

111
00:08:31,110 --> 00:08:34,110
Go to notification microservices in the code window.

112
00:08:34,110 --> 00:08:41,070
We should update these function and click the deploy button and go back to functions.

113
00:08:41,070 --> 00:08:45,930
Open the shipment, go to code window and copy paste from the log operation.

114
00:08:45,930 --> 00:08:53,880
Click to deploy button, go back to functions, open the inventory and come to code window, paste the

115
00:08:53,880 --> 00:08:56,190
location and deploy this button.

116
00:08:56,190 --> 00:09:00,450
And also we have one more micro source, which is the order acknowledgment.

117
00:09:00,540 --> 00:09:04,080
Please come here and paste the logo patient and deploy the function.

118
00:09:04,350 --> 00:09:10,500
Okay, now I'm going to follow the same step, which is the sent publish message from the order topic.

119
00:09:10,530 --> 00:09:14,490
Click the publish message and this subject is an order placed.

120
00:09:14,590 --> 00:09:19,200
Scroll on here you can see the our JSON object, which is the body of the message.

121
00:09:19,200 --> 00:09:24,840
And if you scroll down and click to publish message, this will be triggered or three downstream microservices.

122
00:09:24,840 --> 00:09:27,660
We're using SAS case and lambda function.

123
00:09:27,810 --> 00:09:34,230
So now if you go back to lambda functions and if you open the notification microservices, if you go

124
00:09:34,230 --> 00:09:40,470
to monitor and we've in cloud watch logs, we should see an invocation and also incoming logs.

125
00:09:40,470 --> 00:09:46,260
Yes, there is another log stream if you open this log stream this time we have got the incoming event,

126
00:09:46,260 --> 00:09:47,760
JSON from the SDKs.

127
00:09:47,760 --> 00:09:51,030
You can see the this whole event JSON object.

128
00:09:51,030 --> 00:09:58,140
I'm going to copy this JSON object and open the our pseudocode and come here and paste into event JSON.

129
00:09:58,140 --> 00:10:04,230
So if you come at the beginning of line and remove this line and save these as a JSON, you can see

130
00:10:04,230 --> 00:10:10,020
that we have a record collection since we published one message, the record count is one and in the

131
00:10:10,020 --> 00:10:13,680
record we have message ID received handle and the body information.

132
00:10:13,800 --> 00:10:19,380
And if you expand this body information, this is comes from the Amazon sans.

133
00:10:19,380 --> 00:10:25,740
So that's why it is very long sitting and as you can see that this is type as a notification message

134
00:10:25,740 --> 00:10:26,850
ID is different.

135
00:10:26,850 --> 00:10:31,680
So that means these skills body information also comes from the SAS.

136
00:10:31,680 --> 00:10:39,750
And if you go back to internal body you can see this object is order place and if you come to message

137
00:10:39,750 --> 00:10:46,650
we can see another JSON format which is our actual payload, including the item, iPhone, also status

138
00:10:46,650 --> 00:10:47,490
and so on.

139
00:10:47,490 --> 00:10:52,980
So that means if you come back to our architecture and see that we published message from the Amazon

140
00:10:53,010 --> 00:10:59,790
SAS and we provide a JSON object into message body and this will be subscribed from the Amazon excuse

141
00:10:59,790 --> 00:11:06,870
and also an excuse to create a record and this record pull from the notification lambda microservices.

142
00:11:06,870 --> 00:11:13,710
And that's why we will see these nested object into the incoming event, JSON or Lambda functions.

143
00:11:13,710 --> 00:11:19,170
Well, if you come back to our object, you can see that we have a nested object.

144
00:11:19,170 --> 00:11:23,640
If you go back to notes and come to notes here.

145
00:11:23,670 --> 00:11:24,480
Okay.

146
00:11:25,940 --> 00:11:27,320
But then the page.

147
00:11:27,320 --> 00:11:31,280
And after we check the logs, we saw that we have a nested object.

148
00:11:31,280 --> 00:11:38,630
We can go actual object from the case records, body, sions, topic and the message which is the actual

149
00:11:38,630 --> 00:11:39,410
order message.

150
00:11:39,410 --> 00:11:45,860
So we need to react this order message with this line of code records zero body and the message.

151
00:11:45,860 --> 00:11:51,500
And after that we get the JSON object and we will pass this JSON object in order to reach our actual

152
00:11:51,500 --> 00:11:52,190
object.

153
00:11:52,400 --> 00:11:53,660
Okay, very good.

154
00:11:53,690 --> 00:11:59,660
As you can see that we have successfully create our infrastructure and we have test a published message

155
00:11:59,660 --> 00:12:04,130
from the SNS and we have verified that all these services are working fine.

156
00:12:04,130 --> 00:12:09,830
But by the way, all these infrastructure create operation can be handled with the infrastructure as

157
00:12:09,840 --> 00:12:16,190
called tool in a place like cloud formation, some or CDK, we will see these infrastructure as called

158
00:12:16,190 --> 00:12:18,280
deployment frameworks in the next sections.

159
00:12:18,500 --> 00:12:21,050
So we have successfully create our infrastructure.

160
00:12:21,080 --> 00:12:23,480
Now it is time to focus on the second part.

161
00:12:23,480 --> 00:12:24,980
So what was the second part?

162
00:12:25,010 --> 00:12:26,120
It is developing.

163
00:12:26,120 --> 00:12:29,570
Learn the actual code for interacting message.
