‫Okay, so let's practice Lambda layers.
‫And for this, we'll be following a tutorial by AWS.
‫So let's call a function, Lambda layer demo
‫and the runtime is going to be Python 3.8,
‫and we'll create this function.
‫So we're going to use a layer provided by AWS
‫because it is very complicated for us to create a layer
‫and I just wanna show you how layers work.
‫So for this, let's just go on Google and type,
‫"AWS blog Lambda Layer Scipy, S-C-I-P-Y."
‫So we get a New for Lambda Any Programming Language
‫and share common components.
‫So this is the blog we're looking for,
‫and we'll scroll down,
‫and we want to find the code right here,
‫the Python code that we'll need.
‫Okay. So let's go into our Lambda function.
‫And as we can see in here
‫the Lambda layer demo has currently zero layers.
‫So if you click on layers
‫it takes you to the bottom of your page.
‫And here we can add a layer.
‫So we can get different types of layers.
‫We can get AWS layers or custom layers or specify an ARN.
‫So we'll choose AWS Layers
‫because we haven't created a layer yet.
‫And in here you choose AWS Lambda Python 3.8 SciPy 1x.
‫And then in terms of version
‫just choose the latest version available to us.
‫So this means that this is a layer
‫that has the SciPy Library already compiled
‫for Python 3.8 available for Lambda functions.
‫So we'll click on add, and thanks to this,
‫then we can use code that references the site by library
‫without us attacking the dependencies of that function.
‫So let's take our Python code in here
‫and copy it entirely and then paste it within this window.
‫So we can see the first two lines is import numpy as np,
‫and imports a site by spatial and this function right here.
‫So this means that these things are being imported.
‫And when you have imports
‫on stuff that Lambda function do not know
‫usually you have to pack it with dependencies
‫just the way we did it for node.JS and NPM.
‫Okay. But it turns out that thanks to the layer
‫the dependencies are actually available
‫to our Lambda function, but we didn't have to pack them
‫as dependencies from moving in our code,
‫which is quite cool.
‫So this is the whole power of layers.
‫So let's deploy this function
‫and let's make sure that it is indeed working
‫and that we can leverage these libraries.
‫So let's go into the test tab.
‫We'll just call this one Simple Events
‫and then click on tests.
‫Now the function is executing
‫and we get some information around the log outputs.
‫So it is using numpy.
‫It is creating some matrix
‫and some other matrix, doing some computation,
‫and then computing some random points
‫and finding the smallest sets, containing all points.
‫So nothing important about what this function does.
‫But the important part to remember is that the code itself
‫of the function was using a library here.
‫And that library came
‫from the Lambda layer we had added from before.
‫So there's a whole power of Lambda layers, very quick demo
‫but hopefully it shows you the idea
‫of what you can build
‫and the optimization you can have
‫within your Lambda functions using layers.
‫I hope you liked it.
‫And I will see you in the next lecture.