1
00:00:00,270 --> 00:00:05,730
In this video, we are going to develop hands on labs, which is the greetings solution.

2
00:00:06,000 --> 00:00:07,770
You can see the image on the slide.

3
00:00:07,800 --> 00:00:12,420
We basically create an idea with Islam the function and develop a greeting function.

4
00:00:12,450 --> 00:00:18,810
This function will be invoked from us, which using the seal commands and we are placing the event JSON

5
00:00:18,810 --> 00:00:21,630
object and invoke these functions synchronously.

6
00:00:21,840 --> 00:00:24,720
And this goes back to greeting message to the user.

7
00:00:24,840 --> 00:00:31,100
And we have four main steps that following this project we will develop creating function, zip this

8
00:00:31,110 --> 00:00:34,490
function and create this function with a lambda.

9
00:00:34,500 --> 00:00:39,780
And after that we will invoke this function with commands sensitive and JSON file.

10
00:00:40,230 --> 00:00:41,580
Let's get started.

11
00:00:42,210 --> 00:00:48,300
In order to do that, please open the Visual Studio code and go to the Lecture 62, which is the Hands

12
00:00:48,300 --> 00:00:52,720
On Greeting Project, and we will follow these steps step by step.

13
00:00:52,740 --> 00:00:55,590
The first step is developing lambda function.

14
00:00:55,680 --> 00:01:03,900
To do that, I'm going to go to the index JS file and I will start coding developing our lambda function.

15
00:01:03,990 --> 00:01:11,010
You can see that this is the similar and basic structure of the lambda function and get event parameter

16
00:01:11,010 --> 00:01:13,230
as a parameter of this lambda function.

17
00:01:13,620 --> 00:01:18,900
Okay, let's start our example and we are going to develop greeting project.

18
00:01:18,900 --> 00:01:21,480
So that's why let's write the code.

19
00:01:21,480 --> 00:01:27,660
Now I'm going to parse incoming input, parse the input values.

20
00:01:29,840 --> 00:01:30,590
Think about that.

21
00:01:30,590 --> 00:01:32,720
This is triggering from the Avengers subject.

22
00:01:32,720 --> 00:01:35,630
So first of all, I would like to pass the input values.

23
00:01:35,720 --> 00:01:37,940
And after that, I'm going to generate.

24
00:01:39,400 --> 00:01:40,510
Greeting message.

25
00:01:42,190 --> 00:01:48,370
And after that log and return back message.

26
00:01:48,490 --> 00:01:52,060
So these are the three main steps that I'm going to develop one by one.

27
00:01:52,150 --> 00:01:54,950
So let's start one by one.

28
00:01:54,970 --> 00:02:00,640
First of all, we should start with the parsing, the input values, but before that, we should understand

29
00:02:00,640 --> 00:02:01,700
the incoming event.

30
00:02:01,720 --> 00:02:07,200
Basically, we are expecting the incoming event, which include name, city time and the day.

31
00:02:07,210 --> 00:02:14,170
So before this function, I would like to create some arrays that we can get these day and time information

32
00:02:14,170 --> 00:02:15,100
for that purpose.

33
00:02:15,100 --> 00:02:17,740
I'm defining this array.

34
00:02:17,950 --> 00:02:26,530
And in this array, we we will have weekdays, which is the Monday.

35
00:02:28,430 --> 00:02:29,060
They?

36
00:02:31,290 --> 00:02:32,070
And.

37
00:02:33,780 --> 00:02:42,330
Other days of the week, we have a days array that we can select one of them, one according to incoming

38
00:02:42,330 --> 00:02:42,690
events.

39
00:02:42,690 --> 00:02:49,440
And after that is the same way we have day times, for example morning, afternoon, evening, night

40
00:02:49,440 --> 00:02:50,060
and day.

41
00:02:50,070 --> 00:02:55,080
So that's why I have created two array at the beginning of the index case file.

42
00:02:55,080 --> 00:03:01,500
And after that we will use these days and times in the 100 method when parsing the input values.

43
00:03:01,500 --> 00:03:04,620
So input values I expect the name information.

44
00:03:04,620 --> 00:03:10,960
So that's why I'm defining a name and I expect that the name information should come from the event

45
00:03:10,980 --> 00:03:11,460
name.

46
00:03:11,670 --> 00:03:13,380
And we can also check.

47
00:03:13,380 --> 00:03:15,720
Is that any name or not?

48
00:03:15,750 --> 00:03:17,490
With the control?

49
00:03:17,490 --> 00:03:23,460
Undefined or not, if there is undefined, we can say that write down the you only.

50
00:03:23,490 --> 00:03:28,260
If there is no a problem we can get the event name.

51
00:03:28,470 --> 00:03:31,350
So it's the same code practices.

52
00:03:31,350 --> 00:03:32,940
I will follow the city.

53
00:03:33,710 --> 00:03:41,810
And I'm expecting name on the city information and if there is undefined we can use these pre-defined

54
00:03:41,810 --> 00:03:45,860
words in order to avoid any exception is the same way.

55
00:03:45,860 --> 00:03:51,190
I'm going to continue with the other parameters, which is the time and the day.

56
00:03:51,200 --> 00:03:53,600
So for example, let's create.

57
00:03:54,480 --> 00:03:57,240
Time equal even that.

58
00:03:58,940 --> 00:03:59,570
Time.

59
00:03:59,780 --> 00:04:08,660
But if there is an undefined, we should check the times array and we are waiting times in these array

60
00:04:08,750 --> 00:04:09,320
text.

61
00:04:09,320 --> 00:04:14,000
So if there is not an array, we should perform the default values.

62
00:04:14,000 --> 00:04:20,780
In order to do that, I'm going to modify this line of code according to checking the index of method.

63
00:04:20,780 --> 00:04:25,310
So basically in the incoming event, time should be include our times array.

64
00:04:25,340 --> 00:04:26,450
If not include.

65
00:04:26,450 --> 00:04:28,400
We should set the day as a default.

66
00:04:28,400 --> 00:04:35,540
Otherwise we should set these event time information at the same way I'm going to get the date information.

67
00:04:35,540 --> 00:04:41,120
We have a date array and we are expecting to days into our days array.

68
00:04:41,150 --> 00:04:43,190
Otherwise we set the null operation.

69
00:04:43,280 --> 00:04:43,910
Okay.

70
00:04:43,910 --> 00:04:49,790
We have finished the pass the input values from the incoming event JSON object and now we have this

71
00:04:49,790 --> 00:04:56,240
LED name, city time and date parameters that we can create and generate greeting message.

72
00:04:56,240 --> 00:05:02,990
Now we are going to perform from our main logic, which is the generate greeting message for that purpose

73
00:05:02,990 --> 00:05:04,100
I'm going to create.

74
00:05:05,360 --> 00:05:10,250
We were able, which is a great thing, and we can start good.

75
00:05:11,580 --> 00:05:18,990
And time you can think that a good morning and let me continue with the.

76
00:05:21,370 --> 00:05:22,120
Name.

77
00:05:23,460 --> 00:05:24,720
Good morning name.

78
00:05:24,720 --> 00:05:29,850
And we can give some other information like city.

79
00:05:34,720 --> 00:05:36,670
And we can also say that.

80
00:05:41,660 --> 00:05:43,220
AP the information.

81
00:05:46,540 --> 00:05:48,550
They means we are expecting that.

82
00:05:49,150 --> 00:05:51,790
Happy Tuesday, Wednesday and so on.

83
00:05:52,230 --> 00:05:52,820
Okay.

84
00:05:54,310 --> 00:05:55,220
So very good.

85
00:05:55,240 --> 00:05:57,860
We are finishing our greeting message.

86
00:05:57,880 --> 00:06:03,040
You can think that this is the business logic of the lambda function and we paraphrased some message

87
00:06:03,070 --> 00:06:05,440
according to incoming event JSON object.

88
00:06:05,470 --> 00:06:13,500
And after that I'm going to log these message, see what happens from the last management cloud, which

89
00:06:13,510 --> 00:06:19,540
looks console that look and we can say that message.

90
00:06:21,270 --> 00:06:23,910
A cool one good thing.

91
00:06:24,480 --> 00:06:28,290
Now return back to the greeting message to the lambda function.

92
00:06:29,010 --> 00:06:29,610
Okay.

93
00:06:30,150 --> 00:06:37,890
Basically, we expect an event that triggers to lambda function and includes the name set time and day

94
00:06:37,890 --> 00:06:38,880
information.

95
00:06:38,910 --> 00:06:44,790
And after parsing these these attributes, we are going to generate a greeting message and return back

96
00:06:44,790 --> 00:06:47,820
to this greeting message with logging to Amazon Cloud.

97
00:06:48,660 --> 00:06:53,080
With these attributes, we will do our business logic and create a greeting message and return back

98
00:06:53,100 --> 00:06:55,830
the greeting message as per the incoming event parameters.

99
00:06:56,010 --> 00:07:02,310
So now we have developed our function and if you go to the command section, we have finished the first

100
00:07:02,310 --> 00:07:04,320
part and continue with the second part.

101
00:07:04,350 --> 00:07:05,940
The second part is the same.

102
00:07:05,940 --> 00:07:08,760
We are following the zip file.

103
00:07:08,790 --> 00:07:10,800
I'm going to use compress archive.

104
00:07:10,830 --> 00:07:18,690
Since we have one index case, I'm going to run this command and create a function zip.

105
00:07:19,650 --> 00:07:20,730
I'm sorry.

106
00:07:22,020 --> 00:07:24,840
Let me locate the correct lecture.

107
00:07:28,220 --> 00:07:28,940
Okay.

108
00:07:28,940 --> 00:07:35,270
Now run this command again and create functions under the correct folder structure.

109
00:07:35,360 --> 00:07:36,090
Okay.

110
00:07:36,140 --> 00:07:38,410
The second step is also done.

111
00:07:38,420 --> 00:07:41,450
Now we are going to create lambda function with using CLI.

112
00:07:41,540 --> 00:07:46,280
As you remember that the important thing is we should get the wrong name, which is the lambda execution

113
00:07:46,280 --> 00:07:51,620
role and you should get the error of this role when creating a function.

114
00:07:51,620 --> 00:07:58,510
So after getting these, Aaron, you should run this command, which is the create function command.

115
00:07:58,520 --> 00:08:05,600
You can copy and paste from here and please make sure that your multi-line character is correct windows

116
00:08:05,600 --> 00:08:11,000
using this character and the Mac users using this multi-line character.

117
00:08:11,150 --> 00:08:16,820
Okay, now we are going to create a function which is the greeting function we have developed in index

118
00:08:16,820 --> 00:08:23,810
JS and we zip it the function zip and we are using our existing execution role, which is the Lambda

119
00:08:23,810 --> 00:08:29,150
X hit the enter and this will be create our creating function very good.

120
00:08:29,150 --> 00:08:35,570
So in the last step we are going to create event JSON file and after that we will invoke this function.

121
00:08:35,570 --> 00:08:38,870
So let's create our imagination file.

122
00:08:39,680 --> 00:08:46,550
If you scroll down, we can see that we should create these JSON file and these include name set time

123
00:08:46,550 --> 00:08:48,710
and the information we can follow.

124
00:08:48,710 --> 00:08:54,710
These variables in here is you can set time and they are array in our code.

125
00:08:54,710 --> 00:08:59,630
So that's why I'm giving these parameters from the array values morning and Wednesday.

126
00:09:00,200 --> 00:09:01,010
Okay.

127
00:09:01,040 --> 00:09:06,320
After created this event JSON object, now we can invoke our function.

128
00:09:06,320 --> 00:09:11,870
So in order to do that, if you scroll down you can see the invocation self commands.

129
00:09:11,870 --> 00:09:15,860
We use a lambda invoke command passing the function name.

130
00:09:16,190 --> 00:09:19,340
See that we have created the function name as a greeting.

131
00:09:19,340 --> 00:09:26,420
So that's why make sure that your function name should be the correct which we have created.

132
00:09:26,420 --> 00:09:34,370
So that's what I'm going to copy designer code and paste in here and hit enter and see the invocation.

133
00:09:34,430 --> 00:09:35,140
Okay.

134
00:09:35,480 --> 00:09:40,790
As you can see, that response is 200 success and we will check the response JSON object.

135
00:09:40,790 --> 00:09:46,970
Now, if you open the response that JSON object, you can see that we have generated a greeting message

136
00:09:46,970 --> 00:09:49,940
which is the good morning of Istanbul, happy Wednesday.

137
00:09:49,940 --> 00:09:58,730
So we have successfully create, develop and test our lambda functions and let's all leave and verify

138
00:09:58,730 --> 00:10:00,860
from the management console.

139
00:10:01,160 --> 00:10:03,380
Let me open the message console.

140
00:10:03,410 --> 00:10:06,080
Go to lambda functions.

141
00:10:07,820 --> 00:10:13,640
And if you scroll down you can see that greeting function is created successfully.

142
00:10:13,650 --> 00:10:20,600
If you open this created greeting function and scroll down, you can see that our code is comes in here,

143
00:10:20,600 --> 00:10:22,760
in here deploying successfully.

144
00:10:22,760 --> 00:10:26,870
We have an arrays and we are logging incoming message.

145
00:10:26,870 --> 00:10:32,620
We are passing input values, we are generating greeting message and logging greeting message and return

146
00:10:32,620 --> 00:10:33,800
back to greeting message.

147
00:10:33,890 --> 00:10:38,270
So if you go up and go to monitor and we watch logs.

148
00:10:39,480 --> 00:10:46,410
We have an invocation for testing this function, which commands if you open the latest log stream,

149
00:10:46,770 --> 00:10:51,120
you can see that this is the our incoming message of this lambda function.

150
00:10:51,210 --> 00:11:01,140
And if you look at the other logging message, you can see that this is the logging or greeting message

151
00:11:01,140 --> 00:11:06,990
which is a good morning Mamata Istanbul happy birthday and return back this message to the client application.

152
00:11:07,530 --> 00:11:13,620
So as you can see that we have passed this event object and read from the lambda function check from

153
00:11:13,620 --> 00:11:19,800
the lambda execution, Amazon Cloud Watch logs and now it is time to delete our function.

154
00:11:19,800 --> 00:11:24,420
It is important step before proceeding we should delete our functions.

155
00:11:24,420 --> 00:11:31,230
If you go to the lambda section again and go to the functions, I'm going to select all functions and

156
00:11:31,230 --> 00:11:35,040
come to actions and click the delete and write down delete.

157
00:11:36,760 --> 00:11:39,060
It to the right information and close.

158
00:11:39,070 --> 00:11:41,770
Make sure that your function is data successfully.

159
00:11:41,800 --> 00:11:46,500
And as you can see that we have verified that we are creating a greeting project with hands on loop,

160
00:11:46,510 --> 00:11:49,570
developing creative function and sensory evaluation.

161
00:11:49,600 --> 00:11:54,690
Invoke the synchronously and get back to response successfully with using the commands.
