How To Create Lambda Layer (2 Min) | AWS | Package Python Libraries For Lambda Functions

preview_player
Показать описание
In this tutorial, you'll learn how to create a lambda layer to package libraries and other dependencies that you can use with your AWS Lambda functions. Using layers reduces the size of uploaded deployment archives and makes it faster to deploy your code.



Video Transcript:

Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to add a Python Lambda Layer in AWS. Let's start by navigating to the Lambda service then click on create function and give it a name.

Hit deploy then click on test and give your test event a name then hit save. Click on test again to execute your Lambda function and you should receive an error message saying unable to import module name requests. To fix this error, we're going to create a Lambda layer.

I'm going to copy and paste the virtual environment folder from an existing project which has the requests package installed already. Let's rename this folder to Python which is the requirement according to this AWS guide. Feel free to remove any unnecessary folders or libraries that you don't need in this layer.

Select comparable architectures and runtimes then hit create. Now go back to your Lambda function then click on layers in the function overview section. Click on add a layer button then choose custom layers.

Choose the custom layer that we just created then hit add. Click on the test button and this time your Lambda function should execute without any errors. As you can see the HTML was printed on the console.

There you have it. Make sure you like, subscribe, and turn on the notification bell. Until next time.
Рекомендации по теме
Комментарии
Автор

Thanks so much! Spent forever trying to find out how to do this.Very helpful.

NickHarrington-vs
Автор

Thanks, this video solved my issue of import error after trying a lot many. Thanks bhai

AnshuShah-qo
Автор

Excellent video,
Thank you for sharing.

skanda
Автор

bro thank you, spend two days, getting work with pandas, finally run it using layers

ShubhamRakshe-tx
Автор

Hey Gokce! Thank you very much for the tutorial. Do you know what are the options when yours layers consume more than the limit?

tiagoprelato
Автор

This video was sooo helpful!!! Thank you 🙌

EeveeQueen
Автор

Thanks a lot for this short and to the point video, subscribed!

dhirajkumarsahu
Автор

I have a Question. Once we make a webhook (in my case its webex). For any reason I happen to delete and re-create a new one, would that affect my message to be pushed to AWS Lambda? Should I be making any changes to code-base or aws service when I change/ delete webhook id

manikandannp
Автор

Really useful, it's a pitty on Windows you need to rename the Lib folder and create a new folder inside it, to get it working.

shekelboi
Автор

@Abi Asija What if the zip file is around 0.3Gb size? AWS returns error: Failed to create layer version: Unzipped size must be smaller than 262144000 bytes.
Any idea how to deal with it? Thank you

PantelisPromponas
Автор

No one creates layers like this. Show how to do it from cmd line

mikecmw
Автор

Thanks for the video, it was very clear and precise, In the same way, I wanted to use the azure-identity package with my aws lambda function so for that purpose I created a directory and installed the azure-identity package using the pip command then converted it into a zip file and uploaded it to AWS lambda function along with function.py file. When I ran the script I got the import error stating that
Error Message: {
"errorMessage": "Unable to import module 'lambda_function': cannot import name 'x509' from (unknown location)",
"errorType": "Runtime.ImportModuleError",
"requestId": "3e17800f-0330-40f5-af54-69d860fbfdc1",
"stackTrace": []
} which is the dependent package for the azure-identity package. I would be grateful if you could please help me on how to fix this issue.

ManojKumar-zngf