How to install a Python Dependency on AWS Lambda (2023)

preview_player
Показать описание
Hi all, I have been learning AWS and find Lambda to be a great tool but find it really frustrating to install any Python libraries or dependencies. I have had so many issues with this and have watched just about every tutorial on YouTube for some reason layers never worked for me. The method I found that works is:

(1) Creating a new lambda function
(2) Create a folder on your desktop
(3) Make a python file you can just copy and paste the default Lambda function in here for now
(4) run command prompt / terminal and do pip install [package name] -t . pip3 if on Mac/linux
(5) turn your folder to a zip file and upload to lambda
(6) write your code using your package
(8) Deploy

A problem with this method is I found if you have many dependencies to deploy it will not let you use the inline lambda editor so I may come back to this in the future

0:00 Frustrated with AWS Lambdas
0:50 Create New Lambda
1:10 Create a new folder on Desktop
1:20 Create a python file in folder
1:45 Go into the folder with CMD
2:25 pip install your stuff
2:50 turn folder into a zip file
3:05 Upload the zip file to Lambda
3:50 move files into 1 higher directory
4:20 write python MUST have event, contect
5:20 Fixing the handler name
6:00 Deploying Lambda
Рекомендации по теме
Комментарии
Автор

I figured out that you don't have to "move files into 1 higher directory" if you select all the files and zip them instead of the folder it is in. Thanks this is probably one of the fastest way to deploy something from scratch.

TonyA
Автор

Great Thanks. I try this way, but it is not allowing me to upload my dependencies of more than 50 MB(my zip file is 85 MB). How to handle this?

TheAstroengineer
Автор

Thanks for the video. I have a question - My deployment package became too large to enable inline code editing. Any workaround for this? I am unable to move the files into the higher directory

prajneshshetty
Автор

I struggled with this but now I found you video. Thank you Hicth!

mmu
Автор

AWS tells me "The deployment package of your Lambda function is too large to enable inline code editing. However, you can still invoke your function." and I can't edit my code in the browser. Have you run into this? I was trying to install OpenAI API just like you.

SourVD
Автор

The problem is when deployment zip file is too large, in my case it is 6.2 MB, there is no access to code and directories from ASW console, so you can't modify the directories tree as you did it at 3.52.

maximpobihun
Автор

You did a great job! I was struggling with this for two days. Thank you!

sakthiveljayabal
Автор

Thanks for the content. I also was having hard time with it

erick
Автор

my dependency exceeds zip file upload limit of 50, can you make a tutorial on using docker image for dependencies

aashishpant
Автор

The deployment package of your Lambda function "sheet" is too large to enable inline code editing. However, you can still invoke your function.

how can i see my code and invoke it and edit it

BalajiMustipalli
Автор

Hi Hitch, are you running on Linux? (Looks like Mac OS though..). I am running on Windows and I cannot get it to work. I am wondering if it is because the AWS defaults to Linux environment so Lambda is expecting the dependencies in Linux files?

inkyukim
Автор

There are some issues with creating the lambda zip file through local machine. Since lambda usually uses Amazon Linux 2 OS and here I see you’re using windows OS there maybe some issues with the binary files. Just pointing it out there as I faced this issue when doing it this way.

parvezsekh
Автор

I think that you meant "context" instead of "contect". Good job, the video is great.

leofelipes
Автор

I am trying the same but getting following error
"errorMessage": "Unable to import module 'lambda_function': No module named 'pydantic_core._pydantic_core'",


tried pip installing pydantic but didnt work
also my package size is only 5 mb still aws is showing its too large for inline code editing?

shan_singh
Автор

I'm getting error "errorMessage": "module 'os' has no attribute 'add_dll_directory'", anyone have any idea on how to fix it? :(

vanessabonifaz
Автор

im having error with PIL library showing No module named PIL. is there any solution to this

shubhamrampurkar
Автор

Hello, what if my python library is of big size, like tensorflow, how to handle that now.. (i am doint " import tensorflow ")

loveyourselffirst
Автор

The deployment package of your Lambda function "xyz" is too large to enable inline code editing. However, you can still invoke your function.
It gave caused the following issue. I was trying to install paramiko.
:(
Question: how do I reserve uploading the .zip folder?

yaminisingh
Автор

Create a new directory named package into which you will install your dependencies.

mkdir package

Note that for a .zip deployment package, Lambda expects your source code and its dependencies all to be at the root of the .zip file. However, installing dependencies directly in your project directory can introduce a large number of new files and folders and make navigating around your IDE difficult. You create a separate package directory here to keep your dependencies separate from your source code.

wincevilleaguer
Автор

why you're not using Layers to add these dependencies ?

shadabbarmare