Skip to content Skip to sidebar Skip to footer

How To Upload Python Code With Libraries To Aws Lambda From Windows Local Machine Using Aws Console

I need to use AWS Lambda triggered through API gateway. I have python script which loads a machine learning model from S3bucket and gets input from api call and predicts the result

Solution 1:

First install all the required packages inside a folder in local machine. Also include the main lambda_function.py file inside that folder. Now select all the packages and the python file inside the folder and compress them into a .zip file. Here you have to make sure you compress contents of the folder not the folder itself. Then you can upload the zip file to lambda either directly or through s3. Another point to note is if the python file is named "lambda_function.py" or not. By default lambda assumes the main python file to have "lambda_function.py" name. If you have used any other name, you can change the filename from lambda console under Function code section inside Handler...Hope this helps out.

Solution 2:

You have to make a custom deployment package for lambda either using docker or EC2. It will not work if you make a package in local machine as it will not compile the libaries needed.

here is the complete example, how you will make a custom package , this example packages PILLOW image processing library of python along with the lambda code , you can pack all other libraries you need for your model in the same way in the same package along with PIL

link to example

Remember one thing , in example filename is CreateThumbnail.py, you can give it any name , but always configure your handler in this way filename.handler-function , e.g disco.lambda_handler where disco.py is filename and lambda_handler is code handler module for lambda

Solution 3:

The answers here are technically correct but if you're working on a Windows machine (or anything other than Amazon Linux), you might have a lot of issues putting custom packages in your Python app. Lambda apps run on Amazon Linux so you need to install the packages using that OS or anything as close as possible.

Here's one of my answers which describes how I put together packages for my Lambda app:

https://stackoverflow.com/a/50767639/3023353

Solution 4:

I know that i am a bit late for answering this question but I was facing the same problem with pandas library for python.

this was the link which help me to solve this issue HERE

so the answer in a nutshell is

1.go to here

2.search the library you want to use

3.then go to download option

4.download the file with Linux option

5.Unzip the file in your project folder (I use 7-zip for that)

6.now make a new zip of your project and upload on lambda

Solution 5:

You need to add a Layer for outside python libraries in AWS Lambda.

https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html

The AWS documentation is very bad with examples and for our team it was not easy. Had to manually install a number of libraries but this worked.

Post a Comment for "How To Upload Python Code With Libraries To Aws Lambda From Windows Local Machine Using Aws Console"