Package: lambda-bundler
Lambda BundlerLambda Bundler helps you package your python lambda functions and their dependencies for deployment to AWS.It supports three different modes:Package dependencies for a Lambda layerPackage code-only dependencies from multiple directories for deployment to LambdaPackage your own code and external dependencies into a single zip for deployment to LambdaDependencies will be cached if possible in order to provide a fast build experience.InstallationThe installation is very simple using pip:pip install lambda-bundlerHow to usePackage a Lambda layerfromlambda_bundlerimportbuild_layer_packagepath_to_deployment_artifact=build_layer_package(# You can install the dependencies from multiple# requirement files into a single layerrequirement_files=["path/to/requirements.txt"])# path_to_deployment_artifact now points to a zip archive with the dependencies.Package code directoriesfromlambda_bundlerimportbuild_lambda_packagepath_to_deployment_artifact=build_lambda_package(code_directories=["path/to/package","path/to/other/package],exclude_patterns=["*.pyc"])# path_to_deployment_artifact now contains the path to the zip archivePackage code directories and dependenciesIf you'd like to package your dependencies directly into the deployment artifact you can do that very easily. Please keep in mind, that the size limit for a zipped deployment package is 50MB according to thedocumentationand the content of packages larger than 3MB won't be visible in the code editor in the console.fromlambda_bundlerimportbuild_lambda_packagepath_to_deployment_artifact=build_lambda_package(code_directories=["path/to/package","path/to/other/package],requirement_files=["path/to/requirements.txt],exclude_patterns=["*.pyc"])# path_to_deployment_artifact now contains the path to the zip archiveConfigurationThe library uses a working directory to build and cache packages.
By default this is located in thelambda_bundler_buildsfolder in your temporary directory as determined bypython.If you'd like to change that, you can set theLAMBDA_BUNDLER_BUILD_DIRenvironment variable and point it to another directory.If you're using the Cloud Development Kit and just want to do acdk synthto check your infrastructure code without actually deploying it, you can set the environment variableLAMBDA_BUNDLER_SKIP_INSTALLtotrue. This will skip installing dependencies and bundling the code, which makes the process a lot faster - although it won't work when you try to deploy it with the variable set totrue.Demo / ExampleFor an example of how to use this, I suggest you check out thedemo repositorywhich includes a CDK app that deploys three lambda functions with dependencies of different sizes.
If you take a closer look at thebuild pipelineyou'll see, how effective the caching is.Known LimitationsPackages are downloaded and built on your local machine, that means you might experience problems with libraries that use C-extensions if your platform is not Linux. Building packages with Docker is something I'd like to look into if there's a demand for that.Currently there's no warnings/errors if your deployment package surpasses the Lambda limits - if there's a need for that I'll consider adding those.This is built towards integration with the AWS CDK in python and doesn't work well standalone. I'm considering adding a CLI interface for use in Deployment Pipelines. Let me know if this is something you could use.