1
00:00:00,150 --> 00:00:06,990
In this video, we are going to create infrastructure for event driven microservice architecture with

2
00:00:06,990 --> 00:00:09,720
event bridge squares and lambda functions.

3
00:00:09,750 --> 00:00:14,220
Here you can see the overall architecture that we are going to build in this hands on section.

4
00:00:14,220 --> 00:00:20,010
So basically we will create API, gateway basket microservice, lambda function event bridge custom

5
00:00:20,010 --> 00:00:25,620
event pass as case order queue order microservice lambda function and notification microservice lambda

6
00:00:25,620 --> 00:00:26,280
function.

7
00:00:26,280 --> 00:00:32,400
You can think that the order and notification microservices for target service from the event bridge

8
00:00:32,400 --> 00:00:33,180
event pass.

9
00:00:33,600 --> 00:00:35,990
Okay, let's get started for that purpose.

10
00:00:36,000 --> 00:00:38,220
Open the A management console.

11
00:00:38,220 --> 00:00:44,820
And I would like to start with creating microservices, so please open the Lambda Page and create the

12
00:00:44,820 --> 00:00:45,810
lambda function.

13
00:00:45,810 --> 00:00:49,890
So we will create for the basket microservices.

14
00:00:51,120 --> 00:00:51,780
You can.

15
00:00:53,060 --> 00:00:54,350
Set the basket.

16
00:00:54,440 --> 00:00:55,980
RMS is a function name.

17
00:00:56,000 --> 00:00:59,030
If you scroll down, we can leave as it is for the complications.

18
00:00:59,150 --> 00:01:05,300
Basically, if you go back to our architecture, the basket microservices push and put event to the

19
00:01:05,300 --> 00:01:05,950
event bridge.

20
00:01:06,050 --> 00:01:10,220
So actually it is required permissions for the event which put event.

21
00:01:10,220 --> 00:01:16,940
If you come back to our Lambda Page, if you expand these default role, if you create a new role with

22
00:01:16,940 --> 00:01:23,210
a specific template, I would like to search by event bridge, but there is no predefined policy for

23
00:01:23,210 --> 00:01:23,990
the event bridge.

24
00:01:23,990 --> 00:01:26,930
So that's why I am leaving as it is for all configuration.

25
00:01:26,930 --> 00:01:29,840
After created to function, we will give required permissions.

26
00:01:30,050 --> 00:01:34,730
Please give the name and leave as it is for complications and click the create function.

27
00:01:36,260 --> 00:01:42,890
Look, this will create a new execution role for our lambda function and this role required for the

28
00:01:42,890 --> 00:01:49,430
permission, which is the event for which we can see that I have created a separate lecture and section

29
00:01:49,430 --> 00:01:54,550
folder and in the command text I have listed the required permissions for basket microservices.

30
00:01:54,560 --> 00:02:00,830
This is the event bridge events put event per mission and this will use with event command and we will

31
00:02:00,830 --> 00:02:07,670
find this event policy into the Amazon event page, full access page policy from the A will.

32
00:02:07,700 --> 00:02:08,080
Yes.

33
00:02:08,090 --> 00:02:15,230
So that's why if you open the basket microservices, we will go to configuration permissions open the

34
00:02:15,230 --> 00:02:17,810
role of the execution role.

35
00:02:17,810 --> 00:02:24,200
And in here in basket microservices, we will publish event to the Amazon event page.

36
00:02:24,200 --> 00:02:29,060
For that reason we should have an event bridge events, put event permission into our lambda execution

37
00:02:29,060 --> 00:02:29,540
role.

38
00:02:29,540 --> 00:02:37,150
So come to execution role, click the edit permission and attach policies if you search from the bridge

39
00:02:37,220 --> 00:02:37,880
in here.

40
00:02:39,360 --> 00:02:42,330
You can see some of the operations come in here.

41
00:02:42,330 --> 00:02:47,910
For example, if you look at the written access, we don't access is not including the output event

42
00:02:47,910 --> 00:02:48,960
list object.

43
00:02:48,960 --> 00:02:56,820
So if you come here and select the event page full access, you can see that we can get to all actions

44
00:02:56,820 --> 00:03:00,660
from the event page which including the put events in here.

45
00:03:00,660 --> 00:03:03,390
You can see that we are looking for the events put event.

46
00:03:03,390 --> 00:03:10,320
So that's why please select the Amazon event page full access and attach the policy.

47
00:03:11,820 --> 00:03:15,590
Look, we have successfully attached this policy, which is the event bridge.

48
00:03:15,600 --> 00:03:21,660
So if you come back to basket microservices and refresh this page, we will see that in the configuration

49
00:03:21,660 --> 00:03:23,610
permissions in the resource summary.

50
00:03:23,640 --> 00:03:29,520
Now we can select the event bridge and in the event which you can allow all events actions regarding

51
00:03:29,520 --> 00:03:32,730
the event for the event bridge from the lambda function.

52
00:03:32,880 --> 00:03:40,530
So that means our lambda function basket microservices is ready to put events to event bridge.

53
00:03:40,560 --> 00:03:42,980
Please don't forget the required permissions.

54
00:03:42,990 --> 00:03:44,190
This is very important.

55
00:03:44,220 --> 00:03:45,510
We get the arrows.

56
00:03:45,510 --> 00:03:49,200
These arrows start from the lambda function and goes to impeach.

57
00:03:49,200 --> 00:03:56,250
So that means lambda function is required permission for put event event which in the execution role

58
00:03:56,250 --> 00:04:00,150
and is the same way if you look at the permissions in lambda functions.

59
00:04:00,150 --> 00:04:06,030
So for example, if you look at the ordering microservices, this is pull items from the case.

60
00:04:06,030 --> 00:04:12,480
So that means these ordering Microsofts also required actions and permissions about the pulling items

61
00:04:12,480 --> 00:04:13,470
in the case.

62
00:04:13,470 --> 00:04:20,160
So if you look at the or command text, I have listed the required permissions for basket and order

63
00:04:20,180 --> 00:04:21,600
microservices basket.

64
00:04:21,600 --> 00:04:27,230
Microsoft is required to put events and order microservices requires a skills pull and also dynamic

65
00:04:27,230 --> 00:04:30,810
to be put operation in order to save record in dynamic DB Table.

66
00:04:31,140 --> 00:04:36,420
Okay, if you come back to our architecture, we have verified that which permissions is required and

67
00:04:36,420 --> 00:04:41,460
we have developed and we have created basket microservice and give required permissions.

68
00:04:41,490 --> 00:04:49,050
Now I'm going to go to code section and I would like to add one line of code, which is the log, the

69
00:04:49,050 --> 00:04:55,170
incoming event, click the deploy button and please deploy this log operation incoming event.

70
00:04:55,170 --> 00:05:00,810
And after that, our basket microservices is ready for now for the create infrastructure perspective.

71
00:05:00,810 --> 00:05:07,050
So if you continue or create infrastructure this time, I am going to continue to create API gateway

72
00:05:07,050 --> 00:05:09,330
for the basket microservice operations.

73
00:05:09,330 --> 00:05:15,000
For that purpose, please go to a major console and open the API gateway.

74
00:05:15,000 --> 00:05:20,160
And in the API gateway I will create a rest API for basket microservices.

75
00:05:20,160 --> 00:05:24,330
If you scroll down, see the rest API and click the boot button.

76
00:05:26,160 --> 00:05:35,220
And we will create a rest API and this will be an API and the API name will be the basket API and you

77
00:05:35,220 --> 00:05:36,960
can click the create button.

78
00:05:37,820 --> 00:05:44,210
And in the basket API, we basically create resources and also create methods, come to actions and

79
00:05:44,210 --> 00:05:46,010
start to create resources.

80
00:05:46,040 --> 00:05:47,720
This will be a basket resource.

81
00:05:47,720 --> 00:05:50,750
So that's why I have written the basket.

82
00:05:51,320 --> 00:05:54,890
Create basket resources and own the basket resources.

83
00:05:54,890 --> 00:05:59,140
Please create the method and this time we will only have post method.

84
00:05:59,150 --> 00:06:05,750
This will be the checkout basket http post operation and after that select the lambda function and use

85
00:06:05,780 --> 00:06:07,010
lambda proxy integration.

86
00:06:07,010 --> 00:06:07,910
This is very important.

87
00:06:07,910 --> 00:06:12,520
Please check this box and also provide the function name is a basket MBS.

88
00:06:13,190 --> 00:06:16,040
Click the save button and give the required permissions.

89
00:06:17,660 --> 00:06:25,210
Now we have created our Lambda, our API gateway and expose the API and integrate with the lambda function.

90
00:06:25,220 --> 00:06:31,640
And now I'm going to deploy this API, open the ActionScript Deploy API, create a new stage, which

91
00:06:31,640 --> 00:06:34,490
name is production and click the deploy button.

92
00:06:34,490 --> 00:06:43,490
So we have successfully create our basket API and expose HTTP post method in the inaugural of this.

93
00:06:43,580 --> 00:06:53,240
If we test this URL, you can open the postman and see that we basically copy and paste into in here,

94
00:06:53,900 --> 00:07:01,130
select the post operation and send a request and see that we got the response from the lambda function.

95
00:07:01,130 --> 00:07:04,310
That means we have successfully redirect to lambda function.

96
00:07:04,310 --> 00:07:06,140
If you sent it, we get method.

97
00:07:06,140 --> 00:07:09,530
You can see that we don't have any response missing authentication token.

98
00:07:09,530 --> 00:07:13,750
That means this we get method is not exposed from our API gateway.

99
00:07:14,180 --> 00:07:15,230
Okay, very good.

100
00:07:15,230 --> 00:07:21,800
We have successfully define our API gateway and now we are going to continue to create infrastructure

101
00:07:21,800 --> 00:07:22,280
face.

102
00:07:22,280 --> 00:07:28,790
Well, now I would like to create ordering microservice state database which is the order table dynamo

103
00:07:28,790 --> 00:07:29,600
DB table.

104
00:07:29,600 --> 00:07:38,000
So let's go to the our console, go to Dynamo DB table and create an order table with partition key

105
00:07:38,000 --> 00:07:39,980
is a ID create table.

106
00:07:40,010 --> 00:07:46,550
Table name is order and partition key is ID and if you customize settings, capacity mode should be

107
00:07:46,550 --> 00:07:48,680
on demand and click to create table.

108
00:07:49,530 --> 00:07:50,330
Okay.

109
00:07:50,460 --> 00:07:56,400
If you continue our architecture, you can see that we have done through microservices, which is older

110
00:07:56,400 --> 00:07:58,940
microservice and notification microservices.

111
00:07:58,950 --> 00:08:05,520
So these are the consume the events from the Amazon event breach but ordering microservice use case

112
00:08:05,550 --> 00:08:08,430
one consuming the events for pulling in location.

113
00:08:08,430 --> 00:08:12,000
So now let's create these two microservice lambda function.

114
00:08:12,030 --> 00:08:18,990
If you open the console and go to the lambda functions now I'm going to create need to function.

115
00:08:18,990 --> 00:08:20,660
So create function.

116
00:08:20,670 --> 00:08:27,930
So basically we will create the order microservices, but we should remember that required permissions

117
00:08:27,930 --> 00:08:29,500
for ordering microservices.

118
00:08:29,520 --> 00:08:35,610
If you open the are is code, you can see the order microservice record permissions is here is case

119
00:08:35,610 --> 00:08:37,070
pull and dynamic DB input.

120
00:08:37,080 --> 00:08:39,990
So this is very important to give required permissions.

121
00:08:40,050 --> 00:08:47,280
Please go back to lambda function and in here I have created a new role with the ADA templates because

122
00:08:47,340 --> 00:08:54,200
you can remember that we can use these predefined policies for the case and dynamic.

123
00:08:54,240 --> 00:08:59,790
DB If you search for the case, there is a school's polar permission and if you search for the dynamic

124
00:08:59,790 --> 00:09:04,080
DB, you can see the simple microservice permission to perform operations.

125
00:09:04,650 --> 00:09:09,720
After select this role name and select these policy templates, click the create function.

126
00:09:11,130 --> 00:09:20,700
So this order function we'll subscribe and consume events from Event Bridge and we have Amazon X Order

127
00:09:20,700 --> 00:09:23,330
Q between order microservice and Event Bridge.

128
00:09:23,340 --> 00:09:30,180
For that reason, we should add the Amazon Polar permission and also add the required dynamic DB permission

129
00:09:30,180 --> 00:09:35,760
to interact dynamic DV This is so important feature that we can set the required permissions and created

130
00:09:35,760 --> 00:09:38,130
lambda function with understandable names.

131
00:09:38,310 --> 00:09:44,520
And now if you come back to our order in microservices, we have successfully create these microservices.

132
00:09:44,520 --> 00:09:51,630
If you go to configuration permission, you can see that the creates pull and also dynamic DB required

133
00:09:51,630 --> 00:09:54,360
actions are defined successfully.

134
00:09:54,360 --> 00:10:00,750
So please open the code and place the required log statement in the first line of lambda function.

135
00:10:00,750 --> 00:10:04,650
So this is the incoming event and logging this event click to deploy button.

136
00:10:05,010 --> 00:10:05,760
So very good.

137
00:10:05,760 --> 00:10:08,460
So we have successful define order microservices.

138
00:10:08,460 --> 00:10:14,190
Now I'm going to create another function which is also consume from the subscribe from the event page

139
00:10:14,190 --> 00:10:15,210
you can see in here.

140
00:10:15,210 --> 00:10:17,640
I would like to create a notification microservices.

141
00:10:17,640 --> 00:10:23,850
If you open the create function page of the lambda, basically this will be the notification RMS and

142
00:10:23,850 --> 00:10:27,570
if you scroll down, this is not required any permission.

143
00:10:27,570 --> 00:10:30,840
So that's why I'm creating the default version.

144
00:10:30,840 --> 00:10:37,170
And if you create function, this will be the notification microservices that subscribe to each custom

145
00:10:37,170 --> 00:10:37,950
event pass.

146
00:10:37,950 --> 00:10:44,520
So I'm creating this function by default settings and again we will add the log statement in the code

147
00:10:44,520 --> 00:10:48,540
window, come here and add a log statement and click the deploy button.

148
00:10:49,140 --> 00:10:51,450
So we have finished the microservices.

149
00:10:51,480 --> 00:10:53,820
Now I'm going to focus on the case.

150
00:10:53,820 --> 00:10:58,560
You can see in here we should create a queue which is the order queue.

151
00:10:58,560 --> 00:11:05,850
So please go to the development console and open the simple queue service and create any queue.

152
00:11:08,150 --> 00:11:09,770
And this will be the standard Q.

153
00:11:09,780 --> 00:11:11,090
Q Name should be the order.

154
00:11:11,360 --> 00:11:16,440
Q And if you scroll down, I'm going to leave as it is for all configurations and click the create.

155
00:11:16,460 --> 00:11:17,270
Q button.

156
00:11:17,720 --> 00:11:18,750
Okay, very good.

157
00:11:18,770 --> 00:11:21,530
So we have all also create the order.

158
00:11:21,560 --> 00:11:27,590
Q Now it is time to create event source mapping, pulling invocation as case and lambda function.

159
00:11:27,590 --> 00:11:37,040
So since s case is a durable Q item and receive items from the event page and this will be pulled from

160
00:11:37,040 --> 00:11:41,750
the lambda function, which is the ordinary microservices, we should create event source mapping,

161
00:11:41,750 --> 00:11:47,030
pulling invocation between ordering microservices, lambda function and the space for that purpose.

162
00:11:47,030 --> 00:11:49,120
I'm going to go to lambda function.

163
00:11:49,130 --> 00:11:58,010
If you open the lambda function and go to the order microservices, we should add trigger to a case,

164
00:11:58,010 --> 00:12:03,260
but before that make sure that you have at permission required permissions for the Amazon case and receive

165
00:12:03,260 --> 00:12:03,860
message.

166
00:12:03,860 --> 00:12:11,300
And after that we can capable the trigger to six click the trigger and select the SQL Service and give

167
00:12:11,300 --> 00:12:12,400
the excuse as the order.

168
00:12:12,410 --> 00:12:17,090
Q And if you scroll down, leave this for other complications, click the red button.

169
00:12:17,850 --> 00:12:25,320
So we have successfully a trigger to create an order microservices as you can see that we have successfully

170
00:12:25,320 --> 00:12:28,820
create lambda functions as queues in the next video.

171
00:12:28,830 --> 00:12:34,740
We are continuing to create Amazon event, which is custom event plus to complete our event driven microservice

172
00:12:34,740 --> 00:12:35,520
architecture.
