In this video, we are going to learn how to invoke a lambda function with passing event JSON object
file using the SLA.
So let's get started.
Please open the Visual Studio code and create an Excel folder.
Which name is lecture 4 to 4 and add the command text file.
So as you can see that before starting a new section, I have created a folder and adding the command
text file and locate command line directory for our lecture.
You can see that command line is indicating section seven, election 44.
So now we can start our lecture as you know, that address Lambda functions invoking with the event
objects.
So events are the field of the lambda functions.
So we can also invoke Edwards lambda function with passing event JSON file is note that in the last
video we put the payload into the our command.
You can see the lecture 43 we put the payload is a JSON format key value payload in the invoke command
line.
But in this lecture we should put to create a man JSON file and pasting JSON file as a payload.
So it is good practice to create a white JSON file in order to store these payload data for that purpose
come to under the lecture port for create new file.
To the.
You want, but JSON file.
And in this file, I'm going to basically create any JSON file, which is the key equals volume.
So this very basic case file that we store in the event JSON object and now we are going to invoke these
lambda function pasting these events in file.
Please come to the command, Jason.
Text file in this G6 file, we basically create our invoke commands.
So before pasting these commands, let me copy paste from my window.
Here you can find the lambda IMO command.
We are specifying the function name and we should have to give silly binary format which is the base
64.
And the important part is in here payload is equal to addressing the file, which is the event JSON
file.
This is basically looking at one decent file in the same directory and it is return back to response
into the response JSON file.
And of course we should make this multi line character.
If you remember the multi-line characters in Windows, we are using this character for Mac, we are
using this character.
So let me make it for the windows and see how we can invoke these lambda function.
Och, this is the windows a month.
And now I'm going to copy these commands, which is a slammed in work and I'm working these my function
pacing to these parameters and the important parameter is payload.
Let's copy and paste the terminal, which is the the related lecture folder in here.
Just hit the enter and see the response.
See, that response is coming again Subscore 200 successfully.
And also there is the naive file which is the response JSON.
If you click this JSON file, you can see the body is come from the helo from lambda.
So we can also verify lambda execution from cloud, which logs if you come to cloud logs and come here
and see the latest log, we can verify that we have execution and it is returned to our halo from lambda
message in the body.
Okay, very good.
So if you summarize this section, we basically invoke lambda function.
You can see the image on the slide that shows client invoking a lambda function synchronously sending
the event JSON object.
Lambda basically sends the events directly directly to the function and sends the function response
back to the invoker.
The payload is a string that contains event in adjacent format, the name of the file where the administrator
writes and the response from the function is response is JSON.
So if the function returns an object error, the response object or error in JSON format will be displayed
under the response JSON file.
If the function exists without error, the response will be the include service code and the body information.
So the output from the command which is displayed in the terminal, including the information from the
header source code and the response file.
And this is including all details and process events from the output of the CLI commands.
If the LAMBDA was able to run the function, the function such code will be the 200 even if the functions
turn an error.
So we have successfully invoke lambda function with the event JSON object.
And now I would like to show how we can get the log ID regarding this invocation.
So now we will focus on the gate lock ID function.
Using these commands, we can use the SLA to retrieve logs for an invocation using the log type command
option.
For that purpose, please open the pseudocode and come the command line.
So basically we will use the log type command to retrieve invocation details from the logs.
The response contains a log result feed that contains up to four kilobyte of base64 encoded logs from
the invocation.
So let me write down the example of the retrieving log ID for that purpose.
I'm hoping the command text window and we basically get retrieve a log ID from an invocation.
So I'm going to get this command, which is the lambda invoke and function name is my function and now
I'm going to use log type parameter which is the tail.
This will be get the details from the Amazon Cloud Watch logs.
So let's see how we can invoke our function and how we can get response with the logs.
As you can see that this is the log result FT including details in our invocations.
But this is not so readable, right?
With this log result, we can grab these log items from the Amazon Cloud watch logs, but this is not
readable for make it readable.
We should use base 64 utility to decode these logs so we can use basics for utility for decoding these
logs.
The basics for utility is available for only Linux and Macintosh operating systems.
So we should run this command with the basic command line tool.
So for that purpose, I'm going to.
Use a different command.
Let me say that.
Macintosh.
We can use this command.
As you can see that I'm using the base 64 utility to decode this line of log results.
So but this only works from the Linux and the Macintosh computer.
In order to run this command, I'm going to create a command line.
You can click this here and we can create a new git bash.
Okay.
I'm creating a new page and I can locate for the.
Section.
So and.
Lecture.
What for?
Okay, now I'm going to copy this line of codes, commands and paste in here.
Basically, we are placing the function name and outlook type as a tail, and the important part is
query log result and output text is using the base 6 to 4 utility.
So if you hit the enter this time, you can see that we have detailed information about Amazon Cloud
Watch logs.
These logs come from the Amazon cloud which logs this the start execution and and execution and the
report with giving the information duration, billing, duration, memory, size and so on.
This is exactly what I see in the command line logs, Amazon cloud logs.
You can see in here start and end the report execution.
So we basically get these log information using this command which pacing the log type as a tail and
query log result and using the base 64 and this command only work from the Linux and the macOS operating
system.
So that's why I'm creating any base window based command window in the pseudocode.
So yes, as you can see that we have seen that we have successfully invoke our lambda function with
the event JSON object and we also get the log ID and the CD log details with basic support commands.