1 00:00:00,350 --> 00:00:02,300 ‫Okay, so let's practice Lambda layers. 2 00:00:02,300 --> 00:00:05,710 ‫And for this, we'll be following a tutorial by AWS. 3 00:00:05,710 --> 00:00:09,540 ‫So let's call a function, Lambda layer demo 4 00:00:09,540 --> 00:00:11,993 ‫and the runtime is going to be Python 3.8, 5 00:00:12,860 --> 00:00:14,640 ‫and we'll create this function. 6 00:00:14,640 --> 00:00:18,230 ‫So we're going to use a layer provided by AWS 7 00:00:18,230 --> 00:00:20,910 ‫because it is very complicated for us to create a layer 8 00:00:20,910 --> 00:00:23,070 ‫and I just wanna show you how layers work. 9 00:00:23,070 --> 00:00:25,707 ‫So for this, let's just go on Google and type, 10 00:00:25,707 --> 00:00:30,707 ‫"AWS blog Lambda Layer Scipy, S-C-I-P-Y." 11 00:00:31,770 --> 00:00:35,260 ‫So we get a New for Lambda Any Programming Language 12 00:00:35,260 --> 00:00:36,370 ‫and share common components. 13 00:00:36,370 --> 00:00:38,270 ‫So this is the blog we're looking for, 14 00:00:38,270 --> 00:00:40,040 ‫and we'll scroll down, 15 00:00:40,040 --> 00:00:42,140 ‫and we want to find the code right here, 16 00:00:42,140 --> 00:00:43,810 ‫the Python code that we'll need. 17 00:00:43,810 --> 00:00:46,900 ‫Okay. So let's go into our Lambda function. 18 00:00:46,900 --> 00:00:48,260 ‫And as we can see in here 19 00:00:48,260 --> 00:00:51,060 ‫the Lambda layer demo has currently zero layers. 20 00:00:51,060 --> 00:00:52,690 ‫So if you click on layers 21 00:00:52,690 --> 00:00:54,780 ‫it takes you to the bottom of your page. 22 00:00:54,780 --> 00:00:57,410 ‫And here we can add a layer. 23 00:00:57,410 --> 00:00:58,930 ‫So we can get different types of layers. 24 00:00:58,930 --> 00:01:03,890 ‫We can get AWS layers or custom layers or specify an ARN. 25 00:01:03,890 --> 00:01:05,250 ‫So we'll choose AWS Layers 26 00:01:05,250 --> 00:01:07,670 ‫because we haven't created a layer yet. 27 00:01:07,670 --> 00:01:12,253 ‫And in here you choose AWS Lambda Python 3.8 SciPy 1x. 28 00:01:13,210 --> 00:01:14,190 ‫And then in terms of version 29 00:01:14,190 --> 00:01:16,460 ‫just choose the latest version available to us. 30 00:01:16,460 --> 00:01:18,220 ‫So this means that this is a layer 31 00:01:18,220 --> 00:01:21,530 ‫that has the SciPy Library already compiled 32 00:01:21,530 --> 00:01:25,130 ‫for Python 3.8 available for Lambda functions. 33 00:01:25,130 --> 00:01:27,870 ‫So we'll click on add, and thanks to this, 34 00:01:27,870 --> 00:01:32,420 ‫then we can use code that references the site by library 35 00:01:32,420 --> 00:01:36,450 ‫without us attacking the dependencies of that function. 36 00:01:36,450 --> 00:01:39,110 ‫So let's take our Python code in here 37 00:01:39,110 --> 00:01:44,110 ‫and copy it entirely and then paste it within this window. 38 00:01:45,470 --> 00:01:49,350 ‫So we can see the first two lines is import numpy as np, 39 00:01:49,350 --> 00:01:53,750 ‫and imports a site by spatial and this function right here. 40 00:01:53,750 --> 00:01:56,430 ‫So this means that these things are being imported. 41 00:01:56,430 --> 00:01:57,720 ‫And when you have imports 42 00:01:57,720 --> 00:01:59,930 ‫on stuff that Lambda function do not know 43 00:01:59,930 --> 00:02:01,770 ‫usually you have to pack it with dependencies 44 00:02:01,770 --> 00:02:04,290 ‫just the way we did it for node.JS and NPM. 45 00:02:04,290 --> 00:02:07,320 ‫Okay. But it turns out that thanks to the layer 46 00:02:07,320 --> 00:02:09,310 ‫the dependencies are actually available 47 00:02:09,310 --> 00:02:11,510 ‫to our Lambda function, but we didn't have to pack them 48 00:02:11,510 --> 00:02:13,400 ‫as dependencies from moving in our code, 49 00:02:13,400 --> 00:02:14,233 ‫which is quite cool. 50 00:02:14,233 --> 00:02:15,920 ‫So this is the whole power of layers. 51 00:02:15,920 --> 00:02:18,780 ‫So let's deploy this function 52 00:02:18,780 --> 00:02:21,670 ‫and let's make sure that it is indeed working 53 00:02:21,670 --> 00:02:24,909 ‫and that we can leverage these libraries. 54 00:02:24,909 --> 00:02:26,470 ‫So let's go into the test tab. 55 00:02:26,470 --> 00:02:29,060 ‫We'll just call this one Simple Events 56 00:02:29,060 --> 00:02:31,550 ‫and then click on tests. 57 00:02:31,550 --> 00:02:33,640 ‫Now the function is executing 58 00:02:33,640 --> 00:02:36,610 ‫and we get some information around the log outputs. 59 00:02:36,610 --> 00:02:38,200 ‫So it is using numpy. 60 00:02:38,200 --> 00:02:39,620 ‫It is creating some matrix 61 00:02:39,620 --> 00:02:42,030 ‫and some other matrix, doing some computation, 62 00:02:42,030 --> 00:02:43,721 ‫and then computing some random points 63 00:02:43,721 --> 00:02:47,410 ‫and finding the smallest sets, containing all points. 64 00:02:47,410 --> 00:02:50,580 ‫So nothing important about what this function does. 65 00:02:50,580 --> 00:02:53,890 ‫But the important part to remember is that the code itself 66 00:02:53,890 --> 00:02:57,130 ‫of the function was using a library here. 67 00:02:57,130 --> 00:02:58,530 ‫And that library came 68 00:02:58,530 --> 00:03:01,430 ‫from the Lambda layer we had added from before. 69 00:03:01,430 --> 00:03:04,620 ‫So there's a whole power of Lambda layers, very quick demo 70 00:03:04,620 --> 00:03:07,020 ‫but hopefully it shows you the idea 71 00:03:07,020 --> 00:03:07,853 ‫of what you can build 72 00:03:07,853 --> 00:03:08,970 ‫and the optimization you can have 73 00:03:08,970 --> 00:03:11,470 ‫within your Lambda functions using layers. 74 00:03:11,470 --> 00:03:12,303 ‫I hope you liked it. 75 00:03:12,303 --> 00:03:14,240 ‫And I will see you in the next lecture.