1
00:00:00,150 --> 00:00:06,780
In this video, we are going to create infrastructure for Amazon event with each custom event plus with

2
00:00:06,780 --> 00:00:08,790
following the event driven architecture.

3
00:00:09,120 --> 00:00:12,960
Here you can see the overall architecture that we are going to build in this Hands-On Lab.

4
00:00:13,140 --> 00:00:18,990
Basically, we had created API Gateway Basket, Micro's, Lambda function, case order, queue, order

5
00:00:18,990 --> 00:00:21,780
microservices, notification microservices.

6
00:00:21,780 --> 00:00:25,530
And now we will create the event bridge custom event pass.

7
00:00:26,460 --> 00:00:30,810
So we will create event bridge, Amazon event bridge, custom event pass.

8
00:00:30,810 --> 00:00:33,860
So this will be the basket checkout event pass.

9
00:00:33,870 --> 00:00:38,190
And before we start, we should analyze and design our custom event pass.

10
00:00:38,220 --> 00:00:44,910
We can see the big picture, basically event which has three main core concepts that we need to create.

11
00:00:44,940 --> 00:00:47,220
The first concept is custom event.

12
00:00:47,220 --> 00:00:53,310
Plus we will create a custom event pass into event bridge, which will be name is checkout pass, event

13
00:00:53,310 --> 00:00:53,760
pass.

14
00:00:54,090 --> 00:01:00,030
And after that, in the second step, we will create an event rule with the event pattern.

15
00:01:00,030 --> 00:01:04,290
So we will create a custom event rule, which will be the checkout basket rule.

16
00:01:04,470 --> 00:01:07,370
And after that, we will create targets.

17
00:01:07,380 --> 00:01:13,530
So that means we will create a target of the event bridge as a case and also notification microservices

18
00:01:13,530 --> 00:01:15,120
for our custom event bus.

19
00:01:15,300 --> 00:01:23,130
With this plan basket microservices invoke from the API gateway from the HTTP post request and basket

20
00:01:23,130 --> 00:01:29,340
microservices publish the checkout event checkout basket event to the custom event pass and checkout

21
00:01:29,340 --> 00:01:35,340
basket event pass process the event rule with the event pattern and after that, publish the event to

22
00:01:35,340 --> 00:01:36,660
the target systems.

23
00:01:37,350 --> 00:01:42,240
So let's get started to create these infrastructure into our environment.

24
00:01:42,270 --> 00:01:50,850
Please open the event console and go to Amazon Event Bridge and we will start with creating a custom

25
00:01:50,850 --> 00:01:51,700
event pass.

26
00:01:51,720 --> 00:01:58,950
If you go to the event bus, you can see that we have only default event passes, but this time we are

27
00:01:58,950 --> 00:02:01,760
going to create a new custom event event pass.

28
00:02:01,770 --> 00:02:05,070
You can see in here and click this custom event pass.

29
00:02:05,070 --> 00:02:10,730
So I'm going to give the name as a custom multiverse, which is the checkout basket event pass.

30
00:02:10,740 --> 00:02:17,040
If you scroll on, I don't change any configuration and you can see the store space policy and event

31
00:02:17,040 --> 00:02:19,020
archive and schema discovery.

32
00:02:19,020 --> 00:02:22,800
So give the name the bus, custom bus and click the create button.

33
00:02:23,350 --> 00:02:26,190
Okay, we have created our customers.

34
00:02:26,190 --> 00:02:28,260
Which name is checkout basket event?

35
00:02:28,380 --> 00:02:32,280
And the second step we will create event rule with the event pattern.

36
00:02:32,280 --> 00:02:35,100
So we will create checkout basket rule.

37
00:02:35,280 --> 00:02:41,790
In order to do that, we can go to the our custom event pass and you can see in here the details of

38
00:02:41,790 --> 00:02:44,550
our event plus what I would like to create a rule.

39
00:02:44,550 --> 00:02:50,160
So for that purpose, go to rule section from the left hand side and click the create rule.

40
00:02:50,160 --> 00:02:56,940
And you can see in here we can define a rule in this test, but before that you forgot the very important

41
00:02:57,180 --> 00:02:57,840
thing.

42
00:02:57,840 --> 00:03:01,200
If you go back, basically we will create rules.

43
00:03:01,230 --> 00:03:03,630
First of all, we should select event pass.

44
00:03:03,630 --> 00:03:08,760
Since we have create custom event pass, please select these event pass in here.

45
00:03:08,760 --> 00:03:15,540
We will create rule into our custom event which is the checkout basket event pass select these custom

46
00:03:15,540 --> 00:03:18,810
event pass and after that click the create rule button.

47
00:03:18,810 --> 00:03:24,330
And now I'm going to define a rule name, which name is checkout basket rule?

48
00:03:24,660 --> 00:03:31,950
And if you scroll down you can see that this rule will be create our custom event pass and we will use

49
00:03:31,950 --> 00:03:33,780
rule width and event pattern.

50
00:03:33,960 --> 00:03:37,230
Click the next button and see the next step.

51
00:03:37,650 --> 00:03:40,490
And the next step is will event pattern is.

52
00:03:40,510 --> 00:03:45,870
Remember that we have created event pattern in the last sections and we understand the sample event

53
00:03:45,870 --> 00:03:47,910
section and also event pattern section.

54
00:03:47,910 --> 00:03:54,810
So basically the event source of these custom events should be a base event and I'm leaving as it is.

55
00:03:54,840 --> 00:03:57,810
If you scroll down, I'm not going to sample event.

56
00:03:57,810 --> 00:04:04,410
Now, I will explain after that go directly to event pattern and we will create event pattern from the

57
00:04:04,410 --> 00:04:10,860
custom pattern if you come here and we will provide a custom pattern which will be the JSON object.

58
00:04:10,860 --> 00:04:17,820
And if you copy paste this code, I'm going to copy and paste from the our pattern into common text.

59
00:04:19,380 --> 00:04:21,090
We can copy from here and.

60
00:04:21,960 --> 00:04:22,560
Certain.

61
00:04:23,980 --> 00:04:24,160
Okay.

62
00:04:24,280 --> 00:04:25,930
This will be our event pattern.

63
00:04:26,050 --> 00:04:33,820
So if you go back to our estimation console, we have provide this custom event pattern which expected

64
00:04:33,820 --> 00:04:39,040
detail type is a basket checkout and source is a these are application name.

65
00:04:39,040 --> 00:04:39,640
Okay.

66
00:04:39,670 --> 00:04:45,610
So now if you test this pattern is matching or not, for example, go to sample event and select the

67
00:04:45,820 --> 00:04:46,270
three.

68
00:04:46,270 --> 00:04:52,330
Again, if you select the object, create a three event and test these event pattern from the event

69
00:04:52,330 --> 00:04:53,200
pattern box.

70
00:04:53,650 --> 00:04:55,330
Let me test this event.

71
00:04:55,360 --> 00:05:01,270
Yes, test pattern is you can see that the event didn't match because we are expecting detail type as

72
00:05:01,270 --> 00:05:02,350
a checkout basket.

73
00:05:02,350 --> 00:05:10,330
If you come here and change these object created to the our basket event and the source is what we have

74
00:05:10,330 --> 00:05:11,860
expected, not the SX three.

75
00:05:11,860 --> 00:05:18,310
We are expecting these custom application name so you can specify some some custom object in here.

76
00:05:18,310 --> 00:05:20,890
For example if you copy paste from here.

77
00:05:21,680 --> 00:05:27,680
And come here and change the detailed type as we expected in here.

78
00:05:27,740 --> 00:05:28,670
Think about that.

79
00:05:28,670 --> 00:05:32,340
We are triggering and checkout basket event.

80
00:05:32,360 --> 00:05:35,780
The source will be the application of the OR.

81
00:05:36,670 --> 00:05:43,600
Application name and that means we are checkout event from the basket microservices and there is also

82
00:05:43,600 --> 00:05:49,510
detailed JSON object which including the order ID and order name and so on.

83
00:05:49,510 --> 00:05:57,250
You can think these think that this is the event JSON object that expose and the trigger from the basket

84
00:05:57,250 --> 00:05:58,240
microservices.

85
00:05:58,240 --> 00:05:58,710
Okay.

86
00:05:58,720 --> 00:06:01,810
Let me test this incoming event pattern.

87
00:06:01,810 --> 00:06:03,820
So this time, as you can see that it is made.

88
00:06:03,820 --> 00:06:08,530
So that means we are expecting detail type, checkout basket and source this application name.

89
00:06:08,830 --> 00:06:14,650
After we have defined the event pattern, we can click the next button and the next section is a select

90
00:06:14,650 --> 00:06:15,400
target.

91
00:06:15,670 --> 00:06:18,100
So this is also very important step.

92
00:06:18,100 --> 00:06:24,340
We will create Amazon Case Order Queue and notification microservices for targeting our custom event

93
00:06:24,340 --> 00:06:24,820
pass.

94
00:06:24,820 --> 00:06:27,460
For that purpose I will add to target.

95
00:06:27,460 --> 00:06:31,810
The first target is of course a W services and this will be the case.

96
00:06:32,260 --> 00:06:35,740
You can see the school and specify the queue of the order queue.

97
00:06:36,040 --> 00:06:36,600
Okay.

98
00:06:36,700 --> 00:06:43,150
And I would like to also add another target which is the ADA service and this time lambda function.

99
00:06:44,480 --> 00:06:47,950
Which will be the ah notification microservices.

100
00:06:47,960 --> 00:06:53,540
If you go back to our architecture, you can verify that the subscriber of the event will be excuse

101
00:06:53,540 --> 00:06:55,070
and notification service.

102
00:06:55,300 --> 00:06:55,720
Okay.

103
00:06:55,730 --> 00:07:01,520
These are the targets of the Amazon event customers and we have defined a square SKU and lambda function

104
00:07:01,520 --> 00:07:05,120
and click the next button so we don't have any configure text.

105
00:07:05,150 --> 00:07:07,400
Click next button and review and create.

106
00:07:07,430 --> 00:07:13,880
Here you can see the rule name as a basket checkout basket rule name and you can see the our event pass,

107
00:07:14,510 --> 00:07:18,880
which is the checkout basket event pass and you can see the event pattern.

108
00:07:18,890 --> 00:07:21,490
This is the JSON format, detail type and source.

109
00:07:21,500 --> 00:07:25,610
If you scroll down, we have to target order queue and notification microservices.

110
00:07:25,730 --> 00:07:28,220
After that, please click Create Rule Button.

111
00:07:29,900 --> 00:07:34,100
As you can see, that we have successfully created our rules.

112
00:07:34,130 --> 00:07:39,260
If you can't come to rules and select the event, pass as a checkout basket event pass.

113
00:07:39,290 --> 00:07:41,540
You can see the listed rules in here.

114
00:07:41,570 --> 00:07:43,790
We are rule name is a basket rule name.

115
00:07:43,820 --> 00:07:45,920
Here you can see all the days of the rule.

116
00:07:45,920 --> 00:07:52,190
So that means we have finished the create infrastructure part and for custom event each event pass,

117
00:07:52,220 --> 00:07:57,950
we basically follow these three steps and create custom event pass and create event rule with the event

118
00:07:57,950 --> 00:08:00,320
pattern on the custom event pass.

119
00:08:00,320 --> 00:08:06,110
And lastly, we will create targets which will be the case and notification microservice lambda function.

120
00:08:06,200 --> 00:08:10,220
Now it is time to test our architecture for that purpose.

121
00:08:10,220 --> 00:08:17,330
I'm going to send event from the Amazon event page and see that how invoke this event to our ordering

122
00:08:17,330 --> 00:08:20,480
microservice and notification microservices to do so.

123
00:08:20,510 --> 00:08:26,510
Please open the our analyst console and see that we are in the basket checkout rule.

124
00:08:26,510 --> 00:08:32,930
And if you come back to event buses and come to custom event pass open the custom event pass, you can

125
00:08:32,930 --> 00:08:39,110
see the send event button in here, click this and event button in here and select the event pass as

126
00:08:39,110 --> 00:08:40,160
a custom OnePlus.

127
00:08:40,160 --> 00:08:42,770
And here you can see the event source in here.

128
00:08:42,770 --> 00:08:50,810
So basically if you open the do code, we have created our custom event with details of these attributes.

129
00:08:50,810 --> 00:08:53,360
This is the name, rule name and the event pattern.

130
00:08:53,360 --> 00:09:00,260
So in here when we are sending message event to the event bridge, it is requesting us from the source.

131
00:09:00,260 --> 00:09:06,260
So I'm going to copy and paste as a source from our event pattern in order to match the event pattern

132
00:09:06,260 --> 00:09:09,650
and redirect to event to the target systems.

133
00:09:09,650 --> 00:09:13,190
So please copy paste from the event source in here and the tail type.

134
00:09:13,190 --> 00:09:18,590
Also important, we should check the detail type as a checkout basket and make sure that your detail

135
00:09:18,590 --> 00:09:20,060
type is correct.

136
00:09:20,060 --> 00:09:22,990
And after that we are going to pass the event.

137
00:09:23,000 --> 00:09:23,630
It is.

138
00:09:23,660 --> 00:09:29,690
Think about that basket microservices triggered these events when the basket checkout operation with

139
00:09:29,690 --> 00:09:31,910
the payload of the item and the price.

140
00:09:31,910 --> 00:09:36,500
So please provide the JSON of these attributes in the event detail.

141
00:09:36,530 --> 00:09:42,230
And if you scroll down, we are ready for this and when we are click the send button, this will be

142
00:09:42,230 --> 00:09:45,320
some event JSON object from the Amazon event page.

143
00:09:45,320 --> 00:09:47,990
And here you can see the our JSON object.

144
00:09:47,990 --> 00:09:52,190
I'm going to copy and paste this event to the origin pseudocode.

145
00:09:52,220 --> 00:09:56,420
If you can see here I have create several JSON object and paste in here.

146
00:09:56,450 --> 00:10:04,100
Basically this JSON object produced from the event bridge and this will be run the our event page custom

147
00:10:04,100 --> 00:10:10,970
bus and execute to rule event patterns and after that raw to event to the target systems.

148
00:10:10,970 --> 00:10:14,000
So it will check the detail type and also source.

149
00:10:14,000 --> 00:10:18,800
If these two attributes match, this is going to target systems.

150
00:10:18,800 --> 00:10:22,460
So that means target system or case and notification microservices.

151
00:10:22,460 --> 00:10:27,740
Now we can check the logs from the target system, which is the notification microservice and order

152
00:10:27,740 --> 00:10:28,580
microservice.

153
00:10:28,790 --> 00:10:32,090
Please go to lambda functions and open notification microservices.

154
00:10:32,390 --> 00:10:38,150
So if you open notification and go to monitor and weaving cloud watch logs, we should see the implication

155
00:10:38,150 --> 00:10:41,330
happens when we send event to Amazon event page.

156
00:10:41,390 --> 00:10:46,250
Please open the latest log stream and see that there is incoming event from the event page.

157
00:10:46,250 --> 00:10:52,790
If you copy this file and go back to our registry, the code, I have created a separate JSON file notification

158
00:10:53,060 --> 00:10:59,060
JSON and if I remove this part, you can see that this is exactly the same what we have seen from the

159
00:10:59,060 --> 00:11:00,210
Amazon event breach.

160
00:11:00,560 --> 00:11:01,610
Okay, very good.

161
00:11:01,610 --> 00:11:07,940
So a notification microservices is invoked from the event page and if you go back to our functions and

162
00:11:07,940 --> 00:11:15,110
open the order microservices, these will be also see the invocations if you look at the cloud watch

163
00:11:15,140 --> 00:11:19,970
logs, but this time these order microservices pull event from the space.

164
00:11:19,990 --> 00:11:22,850
Please open the log stream and open the latest log stream.

165
00:11:22,850 --> 00:11:25,460
See that this is incoming event JSON object.

166
00:11:25,460 --> 00:11:28,580
This time we have seen a different object.

167
00:11:28,580 --> 00:11:34,520
So if you go back to our wizard, open the order evaluation and here you can see the incoming event

168
00:11:34,520 --> 00:11:41,990
JSON to order microservices say that it is a record error because all the microservices receive events

169
00:11:41,990 --> 00:11:43,670
from the queue.

170
00:11:43,670 --> 00:11:46,700
That's why we solve the records first of all.

171
00:11:46,700 --> 00:11:52,880
And after that, in the body of the record, you can see the incoming object, which is the our event.

172
00:11:53,030 --> 00:11:58,280
Each event object, we can see the detail type, checkout basket source and so on.

173
00:11:58,280 --> 00:12:03,560
So our actual payload is into our details section.

174
00:12:03,560 --> 00:12:10,190
So that means if we would like to reach actual payload, we go to record zero and after that, get the

175
00:12:10,190 --> 00:12:15,050
body information in the body information, go to detail and decode the detailed information.

176
00:12:15,050 --> 00:12:20,390
As a JSON object, we send the event from the Amazon event page and see the invocations from ordering

177
00:12:20,390 --> 00:12:23,060
microservice and notification microservices.

178
00:12:23,060 --> 00:12:25,630
These are the targets of the Amazon breach.

179
00:12:25,640 --> 00:12:28,980
But what if I would like to differentiate the even.

180
00:12:29,340 --> 00:12:30,990
Into the Amazon event breach.

181
00:12:30,990 --> 00:12:34,810
For example, we are checkout event from basket microservices.

182
00:12:34,830 --> 00:12:40,920
This event is related with older microservices but not related to notification microservices for that

183
00:12:40,920 --> 00:12:41,580
purpose.

184
00:12:41,610 --> 00:12:47,400
With Amazon event event rules, we can filter incoming events and sample events to the corresponding

185
00:12:47,400 --> 00:12:50,190
service what are defined in the rule definition.

186
00:12:50,190 --> 00:12:56,040
So I would like to separate the rule definition and separate the target from notification to all the

187
00:12:56,040 --> 00:12:57,150
network services.

188
00:12:57,180 --> 00:13:01,050
Now we will create a new event rule with event pattern.

189
00:13:01,050 --> 00:13:04,680
Which rule name is a notification rule for that purpose?

190
00:13:04,710 --> 00:13:10,080
Please open the a major console and go to the our event page.

191
00:13:10,080 --> 00:13:16,770
If you open the event page, you can see that we have a rule section and select the our custom event.

192
00:13:16,770 --> 00:13:21,780
Plus we have already checked out basket rule, but this time I would like to create a new rule which

193
00:13:21,780 --> 00:13:23,480
name is notification rule?

194
00:13:23,490 --> 00:13:29,370
So in this rule, if you scroll on this rule again with the event pattern, if you click the next button

195
00:13:29,550 --> 00:13:36,390
and this time if you scroll down in the event button in the custom patterns, we would like to get the

196
00:13:36,390 --> 00:13:40,380
same source, but the detail type will be notification.

197
00:13:40,380 --> 00:13:47,190
So that means we can filter incoming events according to detail type and according to business case

198
00:13:47,190 --> 00:13:49,410
and differentiate the target systems.

199
00:13:49,410 --> 00:13:55,260
So I would like to put this event pattern as a detail type, as a notification and click the next button.

200
00:13:55,710 --> 00:14:01,980
And this time target will be the again lambda function, but the lambda function will be the notification

201
00:14:01,980 --> 00:14:03,020
microservices.

202
00:14:03,030 --> 00:14:06,180
You can think about that if there is any notification event.

203
00:14:06,210 --> 00:14:12,270
This event is not interested from the organic microservices, so that's why the notification event from

204
00:14:12,270 --> 00:14:14,850
directly goes to the notification microservices.

205
00:14:14,850 --> 00:14:20,100
But if there is a checkout event, this event is related for all microservices.

206
00:14:20,100 --> 00:14:24,900
So that's why you check out what is triggered both ordering and notification microservices.

207
00:14:24,900 --> 00:14:31,170
So that's why we can create a separate notification rule in order to target only notification microservices.

208
00:14:31,170 --> 00:14:36,960
So if you continue or create operation, you can select the lambda function notification microservice,

209
00:14:36,960 --> 00:14:39,120
click the next button, click next button.

210
00:14:39,120 --> 00:14:44,010
You can reveal the or rule definition and click the create rule.

211
00:14:46,230 --> 00:14:46,980
Okay.

212
00:14:46,980 --> 00:14:47,770
Very good.

213
00:14:47,790 --> 00:14:51,690
So this event rule only interested in notification microservices?

214
00:14:51,690 --> 00:14:53,500
Not for the checkout microservices.

215
00:14:53,520 --> 00:14:56,190
You can see the custom event pass.

216
00:14:56,190 --> 00:14:59,310
You can see the ah notification rule is created successfully.

217
00:14:59,820 --> 00:15:04,960
As you can see that we have created successfully for our infrastructure on the Hands-On Loop.

218
00:15:04,980 --> 00:15:09,840
By the way, all these infrastructure create operation can be done with the infrastructure Esko tools

219
00:15:09,840 --> 00:15:16,230
in a place like using the cloud formation, some or CDK, we will see these infrastructure as called

220
00:15:16,230 --> 00:15:18,300
deployment frameworks in the next section.

221
00:15:18,450 --> 00:15:21,270
And now it is time to focus on the second part.

222
00:15:21,270 --> 00:15:26,910
As you remember that we have two parts when we are developing Hands-On Lab, the first part was the

223
00:15:26,910 --> 00:15:27,930
create infrastructure.

224
00:15:27,930 --> 00:15:34,290
On the second part is developing Lambda function code for interacting the event which now we will start

225
00:15:34,290 --> 00:15:39,210
to second step which is developing lambda function code for interacting event bridge.
