This docker image makes it possible to package an AWS python lambda function with a single line:
docker run --rm --user $(id -u):$(id -g) -v ${PWD}:/source reboot8/lambda_python_packer:python3.7To generate a minimized package, add envorinment variable MINIMIZE=1.
docker run --rm --user $(id -u):$(id -g) -e "MINIMIZE=1" -v ${PWD}:/source reboot8/lambda_python_packer:python3.7See minimize option for details.
The output will be available under the current folder with the name deploy.zip. By default, the target runtime is python 3.7.
If your pip images requires some dev packages to install, please use the docker image python3.7large, which contains enough packages to install packages like pillow. The commandline becomes:
docker run --rm --user $(id -u):$(id -g) -v ${PWD}:/source reboot8/lambda_python_packer:python3.7largeHere are what this script does:
-
Find requirements.txt in the current folder, and include all the required packages in the final output by running
pipwith it. -
Copy everything in the current folder, and include in the final output.
-
Put the final ourput as deploy.zip in the current directory.
This script currently supports only one option to customize the packaging process. If you need more options, please feel free to submit a wish in the issue tracker, or submit a pull request.
The option MINIMIZE removes the following packges from your deployment:
-
Avoid installing boto3 even if it is in your requirements.txt. Boto3 is already available in the containers that runs lambdas.
-
Rmove pip and setuptools.
Use tags to target at different python runtime.
| Tag | Target Runtime |
|---|---|
| latest | The latest supported by AWS (python 3.7 now) |
| python3.7large | Python3.7 + dev packages |
| python3.7 | python3.7 |
| python3.6 | python3.7 |
| python2.7 | python2.7 |
All issues, comments, pull requests, are very much appreciated. Please contact the maintainer via the GitHub repository of this project.