Тёмный

How to use layers with Lambda functions? 

BiteSize Academy
Подписаться 4,6 тыс.
Просмотров 40 тыс.
50% 1

⚡️ Blog post: www.undefinedapps.com/post/la...
In this video we look at how to use layers with AWS Lambda functions. (with nodejs)
We look at a demo app which uses two npm modules (axios and image-size) which were installed using npm and are part of the bundle. We then extract these modules into a layer. We attach this layer to our function and import and use the modules we extracted.
It has 2 advantages:
- it reduces the size of the bundle
- it makes it possible to re-use the extracted code across several functions.
We also look at how to separate local files and extract them into a layer and then import them from the function.
If you would like to see an example of using layers, check out this video • How to use ImageMagick... in which we use a layer to install ImageMagick to resize images within a lambda function.
⭐️ Subscribe for more content: newsletter.undefinedapps.com/
#lambda #layers #nodejs

Наука

Опубликовано:

 

16 апр 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 38   
@BiteSizeAcademy
@BiteSizeAcademy 2 года назад
⚡️ NEW VIDEO: How to use versioning and aliases to deploy lambda functions? (/w API Gateway) ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-OGMaE63YgEU.html
@rohitkrishnan5456
@rohitkrishnan5456 2 года назад
Hey BiteSize Academy, Great work! I have learnt a lot from your videos.. Can you make a video with a monorepo setup for deploying multiple lambdas (using lambda layers for common modules)? I think it a real world use case and might help a lot of people :)
@nallibtala3800
@nallibtala3800 2 года назад
I will never understand... why every time I have doubts, the official documentation is useless. But forums and users explain really nice
@niravarma
@niravarma 3 года назад
Simple and straightforward. Really helpful.
@nichenjie
@nichenjie 4 года назад
[6:48] If you put `util.js` file inside `node_modules/` folder in the layer, you can do `require('utils')` directly without hardcoding the `/opt` path.
@cristhianvalencia5793
@cristhianvalencia5793 3 года назад
I don't think is a good idea to put things inside the node_modules folder. Unless you have implemented a hook after npm install, the file will not be added automagically (usually the node_modules folder is not committed to the git repository)
@rohitkrishnan5456
@rohitkrishnan5456 2 года назад
@@cristhianvalencia5793 it can be done as part of the build step...maybe util.js lives in a lib folder and gets copied when the lambda layer is deployed
@adrianarizpe7397
@adrianarizpe7397 Год назад
This was extremely helpful and simple. Thank you!
@McMurdoStation
@McMurdoStation 2 года назад
Thanks. I was hoping such a thing was possible but hadn't learned how until this video.
@colin-vandervoort
@colin-vandervoort 2 года назад
Just the right amount of information, and great pacing, thanks!
@luvodlulisa7883
@luvodlulisa7883 2 года назад
This really helped me out, thanks bro.
@matthewhill3556
@matthewhill3556 2 года назад
Perfect explanation! Thanks a lot :)
@lonewolf2547
@lonewolf2547 3 года назад
simple and straight to point
@eduardboiko7219
@eduardboiko7219 Год назад
Was instantly useful, thanks for the video!
@RC-vr7fl
@RC-vr7fl 2 года назад
Great succinct presentation. Many thanks.
@chrismuh5337
@chrismuh5337 2 года назад
thank you very good video and well explained
@ashil816
@ashil816 3 года назад
Really appreciate if you can make a video in kinesis-data-stream and lambda function to consume the stream
@user-qc5il6mh1o
@user-qc5il6mh1o 6 месяцев назад
Thanks! Its helpful :)
@farooquitaha
@farooquitaha 4 года назад
Thanks Sir!!
@karimfayed3050
@karimfayed3050 Год назад
Great Video! It is really helpful. But I do have a question. If I use the layer to just have the node modules, would this be considered preloading dependencies and would make cold starts take less time?
@guillaume5623
@guillaume5623 Год назад
really usefull, thank you
@AnhNguyen-vu7mc
@AnhNguyen-vu7mc 3 года назад
How do you do local testing for layer import? /Opt I assume is not the right path in local machine
@deyvisonborges
@deyvisonborges Год назад
send to local /nodejs/node_modules/your_lib and referece in tsconfig.json paths: { "/nodejs/node_modules/yourpackage": ["/nodejs/node_modules/yourpackage"] } import { item } from "/nodejs/node_modules/yourpackage"
@peterlau2076
@peterlau2076 3 года назад
my life saver
@kfliden
@kfliden Год назад
How would this work with CloudFormation or SAML can you specify a layer there as well? Great video!
@lautarovaleiras3623
@lautarovaleiras3623 8 месяцев назад
awesome
@ZacLow
@ZacLow 3 года назад
you mean, after creating the layer, the codes in the layer don't run anymore? which makes the bundle much faster?
@user-rc1jv7dy5i
@user-rc1jv7dy5i 8 месяцев назад
Why when i use npm i --save dependency1 dependency2 etc... node_modules has more dependencies than it installs
@in.hardikwts
@in.hardikwts Год назад
How youm put this file in function e.g. node_modules, package.json etc file which you remove at 6:35
@paqliam
@paqliam 3 года назад
so your utils file also import a node package (axios). How does it know to get that package from the nodejs folder
@paqliam
@paqliam 3 года назад
Actually I see captain jack comment, and I think that answers my question.
@BiteSizeAcademy
@BiteSizeAcademy 3 года назад
This video explains it in more detail: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RnFowJ130pc.html (How to install npm modules in AWS Lambda?)
@karlang2637
@karlang2637 2 года назад
At time 5:13, line 1 shows the import statement in utils.js. `const axios = require('./nodejs/node_modules/axios')`
@hgiangphan
@hgiangphan Год назад
Silly question: Why using variable type "var" in "var sizeOf" and not "const"?
@kaushalendrapandey2662
@kaushalendrapandey2662 2 года назад
I followed the same steps but "/opt/secrets" is showing "Error: Cannot find module '/opt/secret'\
@sdbyrd56
@sdbyrd56 Год назад
This would be better if you actually demonstrated calling a layer function from the index file. It's unclear from this that you don't have to add any directory structure; you just refer to the module as you would in a non-layered lambda function, but based on this video I tried prefixing 'opt' and then 'nodejs/node_modules', etc. until I realized you don't have to do anythingl.
Далее
Lambda Layers | Theory and Demo with Code
11:02
Просмотров 20 тыс.
Qizim 58-qism | Anons |Nimaga meni bolam o'ladi ?
00:47
How to install npm modules in AWS Lambda?
8:06
Просмотров 53 тыс.
Top 5 Use Cases For AWS Lambda
12:36
Просмотров 80 тыс.
How to deploy a lambda function using github actions?
15:09
How do I deploy AWS Lambda using Terraform?
18:52
Просмотров 42 тыс.
I've been using Redis wrong this whole time...
20:53
Просмотров 339 тыс.
Это Xiaomi Su7 Max 🤯 #xiaomi #su7max
1:01
Просмотров 582 тыс.
iPhone 15 Pro в реальной жизни
24:07
Просмотров 399 тыс.
Samsung laughing on iPhone #techbyakram
0:12
Просмотров 635 тыс.