In this video, we are going to update a lambda function with additional dependencies using a cli.
In the last video, we have already the update on the function quote, but this time we will update
with dependencies.
We didn't add any dependencies into our Node.js lambda function yet, so let's see how we can manage
it.
If our lambda function depends on libraries other than the SDK for JavaScript, we can use MPM to include
them in our deployment package.
We should ensure that the Node.js version in our local environment makes the Node.js version of our
function.
So basically we will use NPM package management tool for installing dependencies in our Node.js lambda
function and deploy with these dependencies.
As we know that in Node.js application, once we add any external package with using the NPM install
command, this will create package that JSON file and note modules folder in order to store these external
library resources.
So that means we should zip all these files when deploying lambda function to the lambda.
Let's write down step by step what we are going to do in this video.
We will install required dependencies into node modules folder.
After that, we will zip function code update function code with the CLI.
And lastly, we will invoke updated lambda function with using SQL Command.
So we have already created my function to and quotes are stored, which is coming from the last section
into the index JS file.
If you can open the we just read your code, you can see in here we will follow this step and we have
deployed my function to with this index CSS code.
Now we can install libraries in the node modules directory using the NPM install command.
So we can think that in this lecture 53 folder, this is the lambda function code and dependencies should
be it should be included under the this folder name.
And we can think that this lecture folder is our lambda function folder and we use Node.js runtime.
So you can think these are Node.js folder of projects which including indexes package JSON file and
node modules folders which including the dependencies.
Okay, let's get started.
If you come to command JS, we will start with the install required dependent dependencies into our
function folder.
So I'm going to install some of the kits, which is the x ray SDK package, which is for the tracing
or invocations.
But I'm using this package for an example and show how we can use dependencies in the lambda functions.
So please copy this command and locate the folder lecture 53 and paste this command into the PowerShell
or your command line and hit enter.
So this creates a folder structure that's similar to our Node.js applications.
You can see that under the lecture 53, we will have no notice and now it is creating package JSON file.
So these three files are created from our NPM install command.
And this folder is because Node.js function and Node.js project.
So see that no modules added the x ray package.
If you come here you can see the x ray package and required package in here.
And if you also check the package JSON file, you can see that there is a dependencies which is a x
SDK.
And here is the version number.
Okay.
Very good.
Now the second step is if you follow the second step, the second step is a function zip to function
quote, zip archive.
So if you scroll down and see the follow the second step, we have several options.
You can see in here in the Windows Manual this time I have to follow the manual version because this
is important.
We should follow the manual zip dependencies cannot be moved we to compress command.
This command is not working for the archiving all the normal dos and under these packages.
So that's why I have to follow manual way.
You can also follow zip command from the Mac users, but Windows users, the compressed archive is not
working, so that's why we should follow the manually.
Zip.
This folder is a function.
So select indexes.
And package JSON files and Node.js modules.
And we will zip this file with our application when we are making zip file of these indexes and package
JSON files.
The important thing is you shouldn't have subfolder into the function zip file when extracting.
It should have these files as expected.
So let me show how we can do that.
So for example, right click and go to the indexes.
Now I'm going to select this file's indexed JS package JSON files anomalous right click sent to compressed
zip folder.
Okay.
This will be the function.
Zip file.
If you double click this function as you can see that these folders has now any folder folders are directly.
You can see under the zip file indexes package JSON and this should be located in the root folder structure.
So this is important when you are zipping an archiving or Node.js, lambda functions.
Okay, now we have finished the second step, but before update the function code, let's check our
existing code on the mission console.
If you go to lambda function, if you come to my function to uncheck the code, this is the our latest
code and there is only one index case file.
But when we are updating this code we should see the package Jasons and Node.js modules in here.
So that means we will update the code with additional dependencies.
Okay, let's come back to our we used to do code and now I'm going to go to the third step, come to
command text and see the third step, which is the update function code.
In order to update function code, you can see in here we will use update function called select command.
Passing the function name and zip file is you remember that we have a function, that zip file which
includes the all required index and package files in here.
So that's why we can easily update our code, copy this command and paste into the your command window
and hit enter.
So this will be update our code with additional dependencies.
Yes, you can see that there is a success response, including the function definitions.
And if you go back to the our management console and if you refresh this page, we will see that our
function will be updated with the Node.js modules.
Okay.
As you can see, that note modules and package JSON file is coming as expected in here.
So basically we have updated successfully and see the difference on the management console.
You can see the folder structure comes appropriately under the my function to I have no modules, indexes
and package JSON files and in the package JSON file you can see the x ray SDK dependency in our application.
And the last step, if you come back to our command window in the last step is invoke updated lambda
function code with the click commands.
In order to do that, we have also JSON file in the event JSON file, we have number one and number
two and we are following the same steps.
If you scroll down, you can see in here we are going to invoke my function to with this event JSON
object and if you paste command in your command window, hit the enter.
You can see the this quote is 200.
If you go to the response JSON file, you can see that the successful body response comes properly in
our application.
Okay.
This was multiply our function and we have multiply with the number one and number two and calculate
total number.
As you can see that we have updated our lambda function with additional dependencies using a double
click commands.