1
00:00:00,300 --> 00:00:07,100
In this video, we are going to do hands on OP which is the ADA Lambda destinations to excuse the data

2
00:00:07,110 --> 00:00:10,490
queue case so you can see the image on the slide.

3
00:00:10,500 --> 00:00:16,020
We will follow the previous hand on loop, but I will choose to create a new lambda function and set

4
00:00:16,020 --> 00:00:22,920
a destination to Amazon X and we will throw an exception in this lambda function and see how this invocation

5
00:00:22,920 --> 00:00:26,040
redirect to Amazon s case is a payload case.

6
00:00:26,310 --> 00:00:29,880
So here you can see the steps that we are going to do one by one.

7
00:00:29,910 --> 00:00:36,960
The first step is throwing an error in Lambda invocations and the second step is retry asynchronous

8
00:00:36,960 --> 00:00:37,830
invocations.

9
00:00:37,830 --> 00:00:45,210
This will be happen from the lambda automatically and the last step is the send destination to the Amazon

10
00:00:45,450 --> 00:00:46,890
case queue records.

11
00:00:46,890 --> 00:00:52,410
So we will follow these steps and perform destination case in the Lambda function.

12
00:00:52,650 --> 00:00:59,580
To do so, please open the Amazon console and go to Lambda functions and we are going to create a native

13
00:00:59,640 --> 00:01:00,720
lambda function.

14
00:01:00,720 --> 00:01:06,510
So click the create function and say that async destination.

15
00:01:08,930 --> 00:01:14,770
Function and I'm going to leave as it is for all configurations and click to create function.

16
00:01:14,780 --> 00:01:20,540
This will be create a new execution role for our newly created these async destination function.

17
00:01:21,280 --> 00:01:27,760
So I will explain how we can add required permission to this lambda function execution role.

18
00:01:27,790 --> 00:01:28,270
Okay.

19
00:01:28,420 --> 00:01:33,550
Our new function is created successfully and if you come the configuration and see the permissions,

20
00:01:33,550 --> 00:01:36,790
new role is created for our lambda functions.

21
00:01:36,940 --> 00:01:37,490
Okay.

22
00:01:37,510 --> 00:01:43,900
If you come to the our code section and if you scroll down, the first thing I should do that I'm going

23
00:01:43,900 --> 00:01:45,370
to throw an exception.

24
00:01:45,370 --> 00:01:50,440
So that means please add this to any error line of code.

25
00:01:50,680 --> 00:01:56,740
We will throwing an exception in this function and I'm going to deploy this function.

26
00:01:56,740 --> 00:02:03,820
So that means this will be returned exception for all invocations because we will test how these lambda

27
00:02:03,820 --> 00:02:06,730
function works in a on failure scenario.

28
00:02:06,760 --> 00:02:08,980
We're setting up the destination.

29
00:02:09,160 --> 00:02:09,940
Okay.

30
00:02:10,060 --> 00:02:15,940
After adding this throw exception line of code, we can test this function with the console.

31
00:02:15,970 --> 00:02:24,730
If you click the test and create any test event name and you can set a Helloworld event JSON object.

32
00:02:24,730 --> 00:02:31,270
And if you go on top of this page, we can save this template and click the test button in order to

33
00:02:31,270 --> 00:02:33,010
invoke our lambda function.

34
00:02:33,130 --> 00:02:38,320
As you can see that the response come in here, we basically return back to error, which is the lambda

35
00:02:38,320 --> 00:02:39,220
error message.

36
00:02:39,220 --> 00:02:43,990
And that means when we invoke our lambda function, it is return also exception.

37
00:02:44,230 --> 00:02:50,530
So when we invoke from a management console, this will invoke request response.

38
00:02:50,530 --> 00:02:53,470
So that means we invoke synchronously.

39
00:02:53,470 --> 00:03:00,820
So that means when we click this test button, this will be run the invoke synchronously in our lambda

40
00:03:00,820 --> 00:03:01,450
function.

41
00:03:01,450 --> 00:03:06,610
But this section we will focus on asynchronous invocation in order to use destinations.

42
00:03:06,820 --> 00:03:10,120
So for that purpose we can go to configuration.

43
00:03:10,120 --> 00:03:15,910
And if you come here and see that, that should be an asynchronous invocation section.

44
00:03:16,720 --> 00:03:22,450
If you click the asynchronous invocation, we can see that we have some configurations that is the maximum

45
00:03:22,450 --> 00:03:25,750
age of event, retry attempts and data services.

46
00:03:25,840 --> 00:03:31,840
If you click the edit button, you can see and change these restrictions and the editor cues.

47
00:03:31,840 --> 00:03:37,730
When this function is asynchronous trigger, see that we can set the retry attempts.

48
00:03:37,750 --> 00:03:42,730
This is the maximum number of times to retry when the function returns an error.

49
00:03:42,760 --> 00:03:49,660
So since our function is returning an error now, this asynchronous invocation should be retried to

50
00:03:49,690 --> 00:03:52,120
attempts, the invocation of the lambda function.

51
00:03:52,120 --> 00:03:55,590
And we can also set the letter Q from the Sans and S case.

52
00:03:55,600 --> 00:03:57,690
So now I am not going to change anything.

53
00:03:57,700 --> 00:04:03,460
I'm going to go back to our lambda function and see the main page of the lambda function.

54
00:04:03,490 --> 00:04:09,250
You can remember that we added the trigger for invocations from the different services.

55
00:04:09,250 --> 00:04:13,480
We added Trigger to API Gateway and also Amazon S3.

56
00:04:13,570 --> 00:04:16,450
And now I'm going to focus on the destination part.

57
00:04:16,450 --> 00:04:23,590
So that means we will designate the invocation to other services after the own success or on failure

58
00:04:23,590 --> 00:04:24,210
issues.

59
00:04:24,220 --> 00:04:28,270
So if you click the add destinations, you can see the configurations.

60
00:04:28,270 --> 00:04:30,230
The first configuration is the source.

61
00:04:30,250 --> 00:04:33,490
This is the type of the invocation that maps to the destination.

62
00:04:33,640 --> 00:04:39,550
We should check the asynchronous invocation and we can also set the three location.

63
00:04:39,550 --> 00:04:43,180
But in our case we will focus on the asynchronous invocations.

64
00:04:43,180 --> 00:04:46,930
And here the second configuration is the condition.

65
00:04:46,930 --> 00:04:53,530
The condition for the own failure or the on on success we can both set and configure on failure and

66
00:04:53,530 --> 00:04:57,630
on success executions for the lambda function set to failure.

67
00:04:57,640 --> 00:05:03,820
And here you can see the destination type, which is the destination services when the invocation happens

68
00:05:03,820 --> 00:05:11,320
on failure or on success, for example, on failure case, we can set the topic case to another lambda

69
00:05:11,320 --> 00:05:13,480
function and event with each event pass.

70
00:05:13,480 --> 00:05:18,160
So we will select the case and we should provide the same.

71
00:05:18,160 --> 00:05:19,480
We can see the destination.

72
00:05:19,480 --> 00:05:20,640
We don't have any.

73
00:05:21,160 --> 00:05:24,160
Q So that's why we can configure our destination.

74
00:05:24,160 --> 00:05:32,170
Now, in order to do that, please go to Amazon case and open a new A management console, Amazon case

75
00:05:32,170 --> 00:05:34,240
page and click the create queue.

76
00:05:34,360 --> 00:05:36,340
I'm going to click.

77
00:05:37,100 --> 00:05:39,870
Create a queue for our definition.

78
00:05:39,920 --> 00:05:45,770
You can see the we are type selecting the type as a standard and the name of this queue should be lambda

79
00:05:45,770 --> 00:05:52,520
queue and I'm not going to change any configuration, so leave as it is and go at the end of the page

80
00:05:52,520 --> 00:05:53,990
and click the create queue.

81
00:05:54,020 --> 00:05:57,800
This will be the our destination queue for lambda function.

82
00:05:57,800 --> 00:06:00,290
So Lambda queue is created successfully.

83
00:06:00,320 --> 00:06:06,500
If you come back to our lambda function, so I'm going to go back to functions and create and open the

84
00:06:06,500 --> 00:06:08,030
page from the beginning.

85
00:06:08,030 --> 00:06:14,260
So now if you click the add destinations, we can configure the destination for lambda function, select

86
00:06:14,260 --> 00:06:19,430
the asynchronous invocation, select on payload and destination type should be the case queue.

87
00:06:19,460 --> 00:06:25,430
Now we have created the lambda queue, so that's why I can set the lambda queue for the destination

88
00:06:25,430 --> 00:06:26,990
of this lambda function.

89
00:06:27,050 --> 00:06:31,220
And after that you can see that there is a warning.

90
00:06:31,220 --> 00:06:32,060
Come here.

91
00:06:32,090 --> 00:06:37,730
Our function execution rule doesn't have permission to send result to destination, so our lambda function

92
00:06:37,730 --> 00:06:41,540
doesn't have permission to add item into queue action.

93
00:06:41,540 --> 00:06:47,420
So by clicking the save button they are going to ADA, which is going to attempt to add permission for

94
00:06:47,420 --> 00:06:47,960
the role.

95
00:06:47,960 --> 00:06:53,870
So if you click the save button, this will be required permission into our lambda execution role.

96
00:06:53,900 --> 00:06:56,600
This is a very good feature from the ADA.

97
00:06:56,780 --> 00:06:57,380
Yes.

98
00:06:57,410 --> 00:07:02,660
We don't need to add the required permission to do our execution roll.

99
00:07:02,690 --> 00:07:03,140
Yes.

100
00:07:03,140 --> 00:07:07,580
As you can see that the illustrations of that are asynchronous invocation.

101
00:07:07,580 --> 00:07:13,520
Our lambda function will be designated to Amazon X and you can see the configurations and destination.

102
00:07:13,520 --> 00:07:19,340
This destination is for the asynchronous invocation and the condition is on failure and the status service

103
00:07:19,340 --> 00:07:20,370
is lambda queue.

104
00:07:20,510 --> 00:07:20,870
Okay.

105
00:07:20,900 --> 00:07:28,820
If you go to our permissions, if you go to permissions, you should require to refresh the page to

106
00:07:28,820 --> 00:07:31,520
see the latest edit permission.

107
00:07:31,520 --> 00:07:36,080
So go to refresh the page and go to permissions and go to resource summary.

108
00:07:36,080 --> 00:07:42,020
If you expand this, you can see the Amazon case is added successfully, which is the allowing send

109
00:07:42,020 --> 00:07:48,410
message these permissions edit from the edit place when we are configured our destination as Amazon

110
00:07:48,420 --> 00:07:48,970
asks.

111
00:07:49,370 --> 00:07:50,750
Okay, very good.

112
00:07:50,750 --> 00:07:53,210
Now it is time to test our destination PID.

113
00:07:53,240 --> 00:08:00,590
We should invoke lambda function asynchronously, so that's why we can't run our test section in the

114
00:08:01,010 --> 00:08:01,910
mission console.

115
00:08:01,910 --> 00:08:06,890
That means we will run a command in order to invoke this function asynchronously.

116
00:08:06,890 --> 00:08:09,890
For that purpose, please open the studio code.

117
00:08:09,920 --> 00:08:14,180
I have created a separate lecture folder and the command text file.

118
00:08:14,180 --> 00:08:20,660
So in the command text file we are going to async invocation to our lambda function we're using to select

119
00:08:20,720 --> 00:08:21,290
commands.

120
00:08:21,290 --> 00:08:26,570
You can see the structure we are using, the lambda invoke command, placing the function name and this

121
00:08:26,570 --> 00:08:31,700
is the important which is the invocation type should be event in order to invoke the lambda function

122
00:08:31,700 --> 00:08:34,970
asynchronously and we can give additional configurations.

123
00:08:34,970 --> 00:08:41,990
So I have prepared a minimum cell command that we will invoke our lambda function asynchronously.

124
00:08:42,020 --> 00:08:47,630
I'm placing the function name, you can copy paste from the function name from the mission console and

125
00:08:47,630 --> 00:08:52,130
give the invocation type as an event and response back to response JSON file.

126
00:08:52,220 --> 00:08:57,260
So for that purpose, I'm going to copy this command and go to a required section folder.

127
00:08:57,350 --> 00:09:02,300
You can go to section folder and after the lecture folder.

128
00:09:03,570 --> 00:09:09,480
Now in here, I'm going to run this command in order to invoke our lambda function asynchronous.

129
00:09:09,780 --> 00:09:12,180
Hit enter and see what happens.

130
00:09:12,300 --> 00:09:14,550
So see that we got the status quo.

131
00:09:14,580 --> 00:09:20,650
202 So that means the lambda asynchronous execution happens successfully.

132
00:09:20,670 --> 00:09:22,370
It doesn't return any response.

133
00:09:22,380 --> 00:09:24,060
You can check the response JSON file.

134
00:09:24,060 --> 00:09:25,760
We don't get any response.

135
00:09:25,770 --> 00:09:28,500
We should check the status from the console logs.

136
00:09:28,500 --> 00:09:35,820
But the idea is that when you see the code as a two under two, that means the asynchronous invocation

137
00:09:35,820 --> 00:09:37,350
execute successfully.

138
00:09:37,590 --> 00:09:43,740
For that purpose, please go to a management console, go to monitor and V cloud watch logs.

139
00:09:43,980 --> 00:09:47,670
So review cloud which looks to see execution logs.

140
00:09:49,080 --> 00:09:55,220
So if you if you come to log stream and open the latest log stream, you can see the logs come in here.

141
00:09:55,230 --> 00:10:01,590
There is lots of logs because I have tried to times when invoke these lambda function asynchronously.

142
00:10:01,650 --> 00:10:07,650
But the idea is that you should see at least three location for the logs.

143
00:10:07,650 --> 00:10:14,700
So because we invoke asynchronous way and interface to retry configuration, if you go to these configurations

144
00:10:14,700 --> 00:10:20,220
of the lambda function and if you go to asynchronous invocation configuration, you can see the retry

145
00:10:20,220 --> 00:10:21,220
attempt is to.

146
00:10:21,240 --> 00:10:29,040
So that's why we have seen two, three times invocation logs when we hit the one invocation synchronous

147
00:10:29,040 --> 00:10:35,070
or lambda function because we invoke asynchronous way and it is to retry configuration and that's why

148
00:10:35,070 --> 00:10:38,880
it tries two times and got two times exceptions.

149
00:10:38,880 --> 00:10:46,170
And after that, the third time when it gets again the same exception it is redirecting to destination

150
00:10:46,560 --> 00:10:47,180
services.

151
00:10:47,190 --> 00:10:52,920
So if you look at the lambda function, you can see the our destination is the Amazon case.

152
00:10:52,920 --> 00:11:01,050
So you can go to Amazon and see the our destination record is come here or not open the Amazon case

153
00:11:01,050 --> 00:11:07,290
and lambda Q We can click this, send the same message and see that we have one available message.

154
00:11:07,290 --> 00:11:12,590
If you pull message from the case, we can see that we have one record.

155
00:11:12,600 --> 00:11:18,870
It is added from the lambda for the execution logs.

156
00:11:18,870 --> 00:11:22,560
You can see the details by adding open the body information.

157
00:11:22,560 --> 00:11:28,200
If you scroll down, you can see the there is an error about the lambda error that we throw from the

158
00:11:28,380 --> 00:11:29,370
lambda function.

159
00:11:29,550 --> 00:11:36,990
So as you can see that we have successfully set our lambda destination and see the record from the Amazon

160
00:11:37,170 --> 00:11:37,620
case.

161
00:11:37,620 --> 00:11:43,680
But also we can also configure our lambda destination is on success.

162
00:11:43,680 --> 00:11:49,810
You can open the lambda function and if you click the add destination, you can see that we can set

163
00:11:49,830 --> 00:11:56,790
a on success and give the destination type as a topic ESC Lambda and even preach.

164
00:11:56,790 --> 00:12:02,880
So this is how we can work with the asynchronous invocation and how we can set up the destinations.

165
00:12:02,880 --> 00:12:06,780
And I would like to show another shortcut for this use case.

166
00:12:06,780 --> 00:12:10,770
For example, we set a dedicated queue for this lambda function.

167
00:12:10,770 --> 00:12:15,420
If there is an exception in two times we are adding the Amazon case, right?

168
00:12:15,450 --> 00:12:16,980
This is the delta queue.

169
00:12:16,980 --> 00:12:23,520
So we can also configure the data to queue, open the configuration and go to asynchronous invocation,

170
00:12:23,550 --> 00:12:24,780
click the edit button.

171
00:12:24,780 --> 00:12:31,050
And if you can see this here that the queue configuration can be set up in the asynchronous configuration.

172
00:12:31,050 --> 00:12:37,310
For example, in here I can select the case and give the our name lambda queue and click this button.

173
00:12:37,320 --> 00:12:40,860
This is exactly the same thing, what we have done in this video.

174
00:12:40,860 --> 00:12:47,280
But I would like to focus to focus on to show you how we can add a destination to our lambda function.

175
00:12:47,550 --> 00:12:48,530
Okay, very good.

176
00:12:48,540 --> 00:12:53,130
Before closing the video, we should clear our resources for that purpose.

177
00:12:53,130 --> 00:12:56,100
Please go to functions and delete functions.

178
00:12:57,360 --> 00:12:59,730
Delete this lambda function.

179
00:13:01,280 --> 00:13:03,660
And also we have create a record.

180
00:13:03,680 --> 00:13:11,870
So please open the Amazon case and go to Qs and make sure that you have delete the Amazon six Q.

181
00:13:13,850 --> 00:13:19,820
Look, we have successfully cleared our resources and we have successfully finished our use case, which

182
00:13:19,820 --> 00:13:20,630
is the aid of Islam.

183
00:13:20,640 --> 00:13:23,270
The destination escapes to the latter case.
