In this video, we are going to continue to understand how a download integrate with events JSON objects.
So now let me do factor the code and log part of our a lambda function as remember that our code is
in here.
You can see that we are looking at the incoming events in here.
But what if we change this code and what happened after that?
This is important because once you understand how lambda triggered with event object, you will understand
any resources triggered a lambda function and how we can handle that trigger from the lambda function
code.
You can see the image if you understand how events triggered the lambda function.
We can also understand how different services trigger our lambda function with even JSON objects.
So now let's modify our code.
So in order to modify our code, please open the visitor code.
And under the lecture 61 we can see that this is the are updated code.
This time we again log into incoming event and after that this time I'm going to log even the name and
surname and return back the event name and the surname.
So let's modify the code and see what happens.
If you go to the function code and remove this line of codes and paste your copy code and deploy the
lambda function.
Now we are ready for the test, our function with this latest code.
We are basically looking to name and surname and return back the name and surname.
If you go to the test section and scroll down and we will send the same event JSON object.
Let's click the test button and see what's happened with these even JSON object.
So as you can see, that execution result is succeed.
But this time we have seen undefined and undefined.
So if you monitor again with the cloud, which logs see what happened.
Open the Ladies Auxiliary and see that this is the incoming event in our function and we are looking
to name and surname.
But these events Jason object not contains name and surname attribute.
So that's why they are undefined and these are returning the undefined message.
So we should also change these incoming event from our lambda function.
So please go to lambda function and go to test block.
And if you scroll down this time I'm going to create an event.
This event name is name, surname, event.
And if you scroll down, we are going to update these events.
Subject So what will be the subject?
If you open the or use the code and go to event object, you can see that it is basically expecting
to us name and surname attributes in the event JSON object.
So I'm copy this line of code and paste in here or you can write by yourself.
And basically this will be the or any event object for the updated lambda function code.
So let me scroll up and save this event.
And now I'm going to taste this event with clicking this test button.
So if you scroll up and see the details now, you can see the response is a successful becomes what
we have expected.
So if we check the logs again between the cloud logs and open the latest log c three, we can see the
logging to hold event object.
You can see that this time it is not undefined.
Name ma'am.
So name is Oscar.
So it is the best practice to log incoming event JSON object in order to understand which attributes
coming to values.
So that's why the first line of code always we have incoming event logging the incoming event.
So this is the best practice to write this line of code.
Let me show this is very important to understand incoming event.
And after that, with the incoming event, we understand that we should reach even JSON object name
and surname attributes and we perform the logging operation and apply the our business logic.
Return this message to our application.
You can see the execution result.
This is the response and these are the logs in our Amazon cloud, which logs, as you can see, that
we have understood that how it is triggered with event JSON object and in the next video we are going
to develop some hands on log in order to understand lambda events and develop lambda functions.