Hi, everyone, and welcome back.
Now into this video, we are going to discuss about the Lambda layers from the practical point of view.
So first, let's go ahead and quickly create a new function.
I'll just call it as my Python function.
The runtime will select it as Python and we'll go ahead and we'll create a function.
Now that our function is created.
This is a simple hello from Lambda function and it will work perfectly.
So you can just say import of request.
You can go ahead and deploy it.
And since this is not available, you will immediately get an error.
Let's try it out.
So when you do a test as expected, it is stating no module name request that is found.
So what you can do either you can upload a deployment package with the appropriate set of libraries
or you can create a centralized layers where you can make use of this specific module for multiple set
of functions.
So we'll be using the layer approach.
So in the lambda, if you'll quickly open up the layers, you can create a layer over here.
Now the next step is to download the appropriate set of modules.
So let me just say PIP install request in this specific folder.
Now, again, at this stage I already have the python and pip that is configured in case if you do not
have that is not an issue, you can just look into it from the practical point of view is concerned.
Apart from that, I'll also be attaching the zip file for better reference.
Now, at this stage, if you'll see in our folder, all the appropriate set of libraries have been installed.
So let's do one thing.
We'll go ahead and we'll zip it.
And I'll do an okay, so this is our compressed file.
So this is what you'll have to upload.
Now, at this stage, our overall practical will fail.
I'll just be describing why.
However, before we do that, I'll just call it as Python base library.
Let's upload the zip file, so we'll upload our layer function here.
Indy compatible architecture.
I'll just say x86 Again, this is optional.
I'll just do a create.
Alright, so our layer is created, you have the appropriate version.
Just make sure that you note the version here, which is version two at this stage.
Let's go back to Lambda in our functions.
We'll go ahead and we'll associate the layer.
We'll select the custom layer.
Now, at this stage we are not able to see our custom layer.
So that means we have made some mistake.
So let's identify what is the mistake that we have made.
So in our Python based libraries, we did not select the compatible runtime and this is the issue.
So what we can do.
Let's select the runtime this time.
And let's upload our package once more.
I'll select the layer function and in the description I'll say Python runtime and we'll create it.
Alright, so this time you have the version three of the layer.
So let's go back to the functions.
Let's go a bit down.
Let's try adding a layer.
This time we are able to see our layer here and just select the appropriate version.
So you have the runtime of Python.
I'll go ahead and I'll click on ADD.
All right.
So once this is, then you can go ahead and quickly test it out.
Lets us call it as zero one.
I'll test it and somehow it is still getting filled.
So if you look into the details, it is still showing no module's name request.
However, if you look into the folder, we do have the appropriate set here and this is where our upcoming
learning related to the layer path comes into picture.
Now, depending upon the runtime that you have, you also have the appropriate folders where you have
to add the modules.
For example, in Node.js, you have Node.js slash, Node.js, underscore module for Python, you have
a folder of Python and so on.
So you have to add it in the appropriate set of directories.
So let's go ahead and try it out once more and see if our function runs.
So this time I'll be going ahead and I'll be creating a folder of Python will copy everything except
a zip file and the python folder by itself.
In fact, I'll cut everything and I'll add it here.
All right?
And what we'll be doing will be compressing the python folder.
And we'll be uploading this.
So going back to our Lambda Layers.
Let's create a new version.
I'll say Python folder just for simplicity.
I'll click on Upload and this time I'll select the Python folder.
I'll click on Open.
Now again here, note that it is stating that for files that are larger than ten, then be consider
uploading using SW three.
So both of the options are present whichever you prefer.
If you have a larger size, better to do it via is three so you can select the compatible architecture
and the appropriate runtime.
And let's do it.
So this time it is based on version four.
So let's go back to Lambda.
We'll go to functions.
Let's go a bit down this time.
Let's edit it will remove this layer three.
And then we'll add a layer for.
So our version number four of the layer is something that will be adding here.
And great.
If things are proper, it should work.
Let's try it out.
So this time I'll say zero two.
Let's test it.
And yes, it is working perfectly well.
We are getting Halo from Lambda.
So that's the high level overview about the practical aspect of layers.
I hope with this you understood things in a better terms and with this will conclude today's video.