In this video, we are going to learn how to invoke a lambda function with using the SLA.
So basically we can invoke a lambda functions with different ways, so we can invoke directly using
a lambda management console or we can use Lambda API or we can use a SDK or we can use a command line
interface which is the SLA.
So in this video we will invoke with the aid.
Obviously, we can also configure other sources to invoke our function or we can configure Lambda to
read from a stream or queue and invoke our function.
We will see all these parts in the upcoming lectures.
Before we start to invoke Lambda function, we should understand the invocation types.
When you invoke a function, we can choose to invoke it synchronously or asynchronously.
With synchronous invocation, we wait for the function to process the event and return the response
with asynchronous invocation, lambda cues, the event for processing and returns the response immediately.
So in this early section of the course, I will mainly invoke with the synchronous way to lambda function.
But after that, in the second part of the course, we will discuss a lambda event driven architectures
and continue with the Invoke Lambda functions asynchronously.
Now let's focus on the synchronous invocations for the lambda functions.
So we have already created a lambda function in the last section with using the measurement console.
You can see in here under the lambda we have my function.
Now it's time to invoke this lambda function with using the ADA.
To do that, please open the pseudocode and come here.
So we should create a new subfolder under the Section seven.
So I'm going to choose, create the section seven and create new folder.
Which name is.
Lecture.
Four, three.
Okay, very good.
So we basically add these similar commands in this lecture 43 folder.
For that purpose, I'm going to copy this command text.
And paste under the lecture portal three.
So I'm going to change the.
Our caption, which is the invoke lambda function using the SLA and we will follow similar commands,
which is the lambda list function and get function.
After that, we will invoke our function using the CLI command.
So basically when we invoke a function synchronously, lambda runs the function and waits for a response
when the function completes.
Lambda returns the response from the functions code with additional data such as the version of the
function that was invoked in order to invoke a function synchronously with the SLA command.
We should use invoke command.
So before proceeding to invoke command, I would like to explain that I'm writing all the commands under
the command takes the file according to lecture number.
So you can see in here lecture 42 and 43 has different command text files which including the related
commands under these text files.
So I have saved these files.
And after that run command in our PowerShell window, I'm saving these commands into text files that
you can copy from there and paste your command window.
So in order to do that, let me write down our invocation command so we can come here and put this command,
which is the invoke command.
So as you can see that we are using the alias lambda in command and specifying function name, which
is the main function in our case.
And we are giving the cell binary format row in base 64 out.
And we basically signed the payload, which is the key value pair and response back to the response
JSON file.
So I will use this command to invoke our function.
In order to do that, please click the terminal and open new terminal.
And this is starting any PowerShell.
If you verify that you for example, you should get function, which is the my function.
Please verify that you have this function name in your environment.
You can see that is the get function response with encoding to all the details.
So now I'm going to run the IMO command for this, my function for that purpose and copy this command
and paste in here and you can see in here a lambda IMO command and giving this configuration.
If you hit the enter you will get exception.
What is this exception?
Invalid request content exception.
So when calling this IMO cooperation, you can get this exception for the could not pass request but
into JSON file.
So as you can see that we are passing this payload in this format, but we have to give different format
in order to solve this exception.
First of all, the important part is providing these command configuration.
The CLI binary format option is required.
If you are using the slide version two, we can also configure this option into our config file.
But you should you should verify that these configurations should be executed in location command.
And after that we should change this payload according to double code, another required operation.
In my case, I need to change.
This payload is a double code.
You can see that we have single code.
I'm going to.
That's the correct one.
You can see that key and volume information required to double code to understand the correct JSON format.
So now I think it is okay, let's copy this command and paste again in here and hit enter.
Okay.
Now you should see the following output response.
That means we have successfully invoke our lambda function.
And you can also see that there is a response JSON generated in our main folder.
But this should be in here.
Okay.
Yes, I'm moving this response station under the lecture 43 and in here you can see that such code is
200 success and the body is the helo from lambda.
This response file creates from the outside because we should run these commands under the.
Lecture folders.
You can see in here, I'm going to come section seven and you can see in here lecture 4 to 3.
Now we should run this command under this folder to see correct response to subject.
Okay, these are in location command and this is the response.
So that means we have successfully run the lambda functions.
We can also verify lambda execution from Amazon Cloud which logs?
Let's open the function, go to function monitor and open the v logs in the cloud.
Watch.
And now I'm going to verify that we have invoked our function successfully in here from the cloud commands.
Very good.
And we can also set the multi-line character when running invoke command and command window.
So if you come back to our we just do code.
You can see in here under the command text, we are saving all the commands in this text file.
Now I'm going to explain how we can make it multi-line characters.
So for Windows.
I'm going to add Multi-line character with this character.
You can see in here, I can run my command with multi-line characters.
Let's verify with the cell.
Let me close this one and create a new terminal.
And if you pass this command, you can see that I can make multi-line character.
But of course, before that, I would like to.
Locate.
Correct folder.
Now I'm going to run again, hit the enter and see that the status code return to 200 success.
So that means I can invoke our lambda function with multi-line characters, but if you are using to
make the multi-line character is differentiate.
So that's why I'm also pasting in here.
This.
You can see in here, Windows is using this character and Mac is using this character to make it multi-line
characters.
As you can see that we have successfully invoke our lambda function and it returns 200 success and we
have verified that this is running from our measurement console.
In the next video we are going to invoke with passing the event JSON object.