Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python AWS Lambda deploy - Zappa package without Zappa requirements

I want to package and deploy a simple project on AWS Lambda, using Zappa, but without the Zappa requirements overhead.
Given this simple scenario:

lambda_handler.py

def handle(event, context):
    print('Hello World')  

I have a deploy.sh script that does that:

#!/usr/bin/env bash
source venv/bin/activate
zappa package -o lambda.zip
aws lambda update-function-code --function-name lambda-example --zip-file fileb://./lambda.zip

This works, BUT the final lambda.zip is way bigger then it needs to be: enter image description here

I know that for this specific case the Zappa is not needed, but in the real project I'm using some libraries that requires https://github.com/Miserlou/lambda-packages, and using Zappa is the simplest way to install them.

How do I generate the python lambda package without this overhead?

like image 224
joaoricardo000 Avatar asked Sep 27 '18 22:09

joaoricardo000


1 Answers

First, you can use slim_handler that allows to upload larger files than 50M. Second, as @bddb already mentioned you can eclude some files such as .pyc, zip etc with the exclude property. Please find more details here:

https://github.com/Miserlou/Zappa#package

Here is an example how your zappa_settings.json could look like:

 {
    "dev": {
...
        "slim_handler": false, // Useful if project >50M. Set true to just upload a small handler to Lambda and load actual project from S3 at runtime. Default false.
        "exclude": ["*.gz", "*.rar"], // A list of regex patterns to exclude from the archive. To exclude boto3 and botocore (available in an older version on Lambda), add "boto3*" and "botocore*".
    }
}
like image 129
Rene B. Avatar answered Sep 25 '22 23:09

Rene B.