In this video we are going to understand how a lambda triggered with event json object.
You can see the image.
We are creating an event and trigger a lambda function code and arrange and develop our function code
with incoming JSON object.
Let's get started.
Please open the A machine console and go to Lambda functions.
Create a function.
We use a lambda function for the backend or API.
For this example, I also and also during the course, I would like to use Node.js versions as a runtime
so the function name will be the new function and runtime should be the Node.js and architecture live
as it is and the permission leave as it is and click the create function.
This is a standard lambda function and this example function returns a 200 response to client and the
text will be the halo from the lambda.
If you scroll down, you can see the code section is the standard lambda function.
It is turning source code and the button information.
Okay.
Before we start, first of all, we should understand how a lambda triggered with the event JSON objects.
So we opened our lambda function and go to the test section.
So if you scroll down under the test, you can see that these are the test events we set that lambda
triggered with events, so we should provide at least one event from anywhere.
So in this test section, we can invoke our function with a test event.
Also, we can choose a template I will show you soon, but let's see this helloworld template.
If you scroll down, you can see the templates by default it's coming the Helloworld template and this
is the Helloworld template event object so we can give the name.
The test you want.
And if you scroll down.
Select the template helloworld and scroll up.
We can see the save button and click the test button, but before click the test button you can check
the event JSON object.
So that means we will send this JSON object to our lambda function.
So let's click the test button and see how we can send these images.
Okay.
So as you can see that the execution result is succeed and if you expand these details, you can see
the source code is 280 is hello from lambda function.
So we can successfully invoke our lambda function but we don't interact with the incoming even JSON
object yet.
So if you look at the our code window, we don't have any interaction with this even JSON object, we
only return this response.
But we should also interact with the event JSON object because now we are know that we are sending this
information about this Helloworld JSON object and we can interact with these attributes, which is the
key 1 to 3.
So let's modify our code with getting and writing events value from the Lambda function.
I'm going to modify our lambda function in the management console, but you can get the quote from the
OR.
We just do code window under lecture 60.
If you go to index JS, you can see that this is the are updated code.
So I would like to also log into incoming event.
So basically in this line of code, we are logging the incoming event JSON object as adjacent structure
and after that we will interact incoming event object attributes.
So event is key 1 to 3 attributes so that we can interact with logging this information.
And after that we have returned the first key of the event JSON object.
So this is our updated code.
So that's why let's copy this in line of the code and code, go back to our dashboard management console
and please remove this line of codes and paste in here.
Of course we should deploy for the deploying our function and now we can test again with this event
object.
We verified that our event will be this way key.
One, two, three and one, two, three.
If I click the test button now, I'm going to interact with the incoming event JSON object and return
back to volume one.
So how we can interact that we can check from the monitoring with this function.
If you go to monitor and we include watch logs, we will see the logs on the cloud watch.
And if you open the latest logs, you can see that the first line of two are logging the incoming event.
This is the incoming event that we verified from the Lambda function and these are the logs that we
are logging in for logs, volume one, volume two and three.
And the last operation is returning to volume one operation.
So we can verify that this is the following the same steps that we develop in our function.
You can see the function code in here and we have verified that we proceed these lines and execute to
logs, right, to logs in this way.
Okay.
We verified that.
Understand that when we send any test or lambda function, we are signing these event JSON objects and
we can interact with evaluation object to reaching these attributes into our code of the lambda function.
So you can see that we have locked every item into event request and return back to volume one.
In the next video.
We will continue to do some advanced event objects.