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:
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?
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*".
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With