You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python script to package a Python function for deploying to AWS Lambda
2
+
Python command-line (CLI) tool to package a Python function for deploying to AWS Lambda, and possibly other
3
+
cloud platforms.
4
+
5
+
This tool builds a ZIP file from a virtual environment with all depedencies installed that are to be included in the final deployment asset. If the content is larger than AWS Lambda's maximum unzipped package size of 250 MiB,
6
+
then this tool will employ the ZIP-inside-ZIP (nested-ZIP) workaround. This allows deploying Lambdas with large
7
+
dependency packages, especially those with native code compiled extensions like Pandas, PyArrow, etc.
8
+
9
+
This technique was originally pioneered by [serverless-python-requirements](https://github.com/serverless/serverless-python-requirements), which is a NodeJS (JavaScript) plugin for the [Serverless Framework](https://github.com/serverless/serverless). This technique has been improved here to not require any special imports in your entrypoint source file. That is, no changes are needed to your source code to leverage the nested ZIP deployment.
10
+
11
+
The motivation for this Python tool is to achieve the same results as serverless-python-requirements but with a
12
+
purely Python tool. This can simplify and speed up developer and CI/CD workflows.
13
+
14
+
One important thing that this tool does not do is build the target virtual environment and install all of the
15
+
dependencies. You must first generate that with a tool like [Poetry](https://github.com/python-poetry/poetry) and the [poetry-plugin-bundle](https://github.com/python-poetry/poetry-plugin-bundle).
arg_parser.add_argument("venv_dir", type=str, help="The directory path to the virtual environment to package into a zip file")
20
+
arg_parser.add_argument("--project", type=str, default='pyproject.toml', help="The path to the project's pyproject.toml file. Omit to use pyproject.toml in the current working directory.")
21
+
arg_parser.add_argument("--output-dir", type=str, default='.', help="The directory path to save the output zip file. Default is the current working directory.")
22
+
arg_parser.add_argument("--output", type=str, default='', help="The full file path for the output file. Use this instead of --output-dir if you want total control of the output file path.")
0 commit comments