8

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?

2
  • Did you try using the exclude setting for zappa package? github.com/Miserlou/Zappa#package Also it doesn't seem like everything in lambda-packages was added so I assume all of those packages you see are actually needed by your application? Commented Sep 28, 2018 at 3:05
  • Not really, all those packages are Zappa requirements. Zappa does a lot more than just packaging. The exclude would work, but some packages have some shared dependencies, so it is not that simple, some verification would be required. Commented Sep 28, 2018 at 15:40

1 Answer 1

3

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*".
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.