In this video, we are going to develop hands on labs, which is the greetings solution.
You can see the image on the slide.
We basically create an idea with Islam the function and develop a greeting function.
This function will be invoked from us, which using the seal commands and we are placing the event JSON
object and invoke these functions synchronously.
And this goes back to greeting message to the user.
And we have four main steps that following this project we will develop creating function, zip this
function and create this function with a lambda.
And after that we will invoke this function with commands sensitive and JSON file.
Let's get started.
In order to do that, please open the Visual Studio code and go to the Lecture 62, which is the Hands
On Greeting Project, and we will follow these steps step by step.
The first step is developing lambda function.
To do that, I'm going to go to the index JS file and I will start coding developing our lambda function.
You can see that this is the similar and basic structure of the lambda function and get event parameter
as a parameter of this lambda function.
Okay, let's start our example and we are going to develop greeting project.
So that's why let's write the code.
Now I'm going to parse incoming input, parse the input values.
Think about that.
This is triggering from the Avengers subject.
So first of all, I would like to pass the input values.
And after that, I'm going to generate.
Greeting message.
And after that log and return back message.
So these are the three main steps that I'm going to develop one by one.
So let's start one by one.
First of all, we should start with the parsing, the input values, but before that, we should understand
the incoming event.
Basically, we are expecting the incoming event, which include name, city time and the day.
So before this function, I would like to create some arrays that we can get these day and time information
for that purpose.
I'm defining this array.
And in this array, we we will have weekdays, which is the Monday.
They?
And.
Other days of the week, we have a days array that we can select one of them, one according to incoming
events.
And after that is the same way we have day times, for example morning, afternoon, evening, night
and day.
So that's why I have created two array at the beginning of the index case file.
And after that we will use these days and times in the 100 method when parsing the input values.
So input values I expect the name information.
So that's why I'm defining a name and I expect that the name information should come from the event
name.
And we can also check.
Is that any name or not?
With the control?
Undefined or not, if there is undefined, we can say that write down the you only.
If there is no a problem we can get the event name.
So it's the same code practices.
I will follow the city.
And I'm expecting name on the city information and if there is undefined we can use these pre-defined
words in order to avoid any exception is the same way.
I'm going to continue with the other parameters, which is the time and the day.
So for example, let's create.
Time equal even that.
Time.
But if there is an undefined, we should check the times array and we are waiting times in these array
text.
So if there is not an array, we should perform the default values.
In order to do that, I'm going to modify this line of code according to checking the index of method.
So basically in the incoming event, time should be include our times array.
If not include.
We should set the day as a default.
Otherwise we should set these event time information at the same way I'm going to get the date information.
We have a date array and we are expecting to days into our days array.
Otherwise we set the null operation.
Okay.
We have finished the pass the input values from the incoming event JSON object and now we have this
LED name, city time and date parameters that we can create and generate greeting message.
Now we are going to perform from our main logic, which is the generate greeting message for that purpose
I'm going to create.
We were able, which is a great thing, and we can start good.
And time you can think that a good morning and let me continue with the.
Name.
Good morning name.
And we can give some other information like city.
And we can also say that.
AP the information.
They means we are expecting that.
Happy Tuesday, Wednesday and so on.
Okay.
So very good.
We are finishing our greeting message.
You can think that this is the business logic of the lambda function and we paraphrased some message
according to incoming event JSON object.
And after that I'm going to log these message, see what happens from the last management cloud, which
looks console that look and we can say that message.
A cool one good thing.
Now return back to the greeting message to the lambda function.
Okay.
Basically, we expect an event that triggers to lambda function and includes the name set time and day
information.
And after parsing these these attributes, we are going to generate a greeting message and return back
to this greeting message with logging to Amazon Cloud.
With these attributes, we will do our business logic and create a greeting message and return back
the greeting message as per the incoming event parameters.
So now we have developed our function and if you go to the command section, we have finished the first
part and continue with the second part.
The second part is the same.
We are following the zip file.
I'm going to use compress archive.
Since we have one index case, I'm going to run this command and create a function zip.
I'm sorry.
Let me locate the correct lecture.
Okay.
Now run this command again and create functions under the correct folder structure.
Okay.
The second step is also done.
Now we are going to create lambda function with using CLI.
As you remember that the important thing is we should get the wrong name, which is the lambda execution
role and you should get the error of this role when creating a function.
So after getting these, Aaron, you should run this command, which is the create function command.
You can copy and paste from here and please make sure that your multi-line character is correct windows
using this character and the Mac users using this multi-line character.
Okay, now we are going to create a function which is the greeting function we have developed in index
JS and we zip it the function zip and we are using our existing execution role, which is the Lambda
X hit the enter and this will be create our creating function very good.
So in the last step we are going to create event JSON file and after that we will invoke this function.
So let's create our imagination file.
If you scroll down, we can see that we should create these JSON file and these include name set time
and the information we can follow.
These variables in here is you can set time and they are array in our code.
So that's why I'm giving these parameters from the array values morning and Wednesday.
Okay.
After created this event JSON object, now we can invoke our function.
So in order to do that, if you scroll down you can see the invocation self commands.
We use a lambda invoke command passing the function name.
See that we have created the function name as a greeting.
So that's why make sure that your function name should be the correct which we have created.
So that's what I'm going to copy designer code and paste in here and hit enter and see the invocation.
Okay.
As you can see, that response is 200 success and we will check the response JSON object.
Now, if you open the response that JSON object, you can see that we have generated a greeting message
which is the good morning of Istanbul, happy Wednesday.
So we have successfully create, develop and test our lambda functions and let's all leave and verify
from the management console.
Let me open the message console.
Go to lambda functions.
And if you scroll down you can see that greeting function is created successfully.
If you open this created greeting function and scroll down, you can see that our code is comes in here,
in here deploying successfully.
We have an arrays and we are logging incoming message.
We are passing input values, we are generating greeting message and logging greeting message and return
back to greeting message.
So if you go up and go to monitor and we watch logs.
We have an invocation for testing this function, which commands if you open the latest log stream,
you can see that this is the our incoming message of this lambda function.
And if you look at the other logging message, you can see that this is the logging or greeting message
which is a good morning Mamata Istanbul happy birthday and return back this message to the client application.
So as you can see that we have passed this event object and read from the lambda function check from
the lambda execution, Amazon Cloud Watch logs and now it is time to delete our function.
It is important step before proceeding we should delete our functions.
If you go to the lambda section again and go to the functions, I'm going to select all functions and
come to actions and click the delete and write down delete.
It to the right information and close.
Make sure that your function is data successfully.
And as you can see that we have verified that we are creating a greeting project with hands on loop,
developing creative function and sensory evaluation.
Invoke the synchronously and get back to response successfully with using the commands.