Skip to main content

A utility to bundle python code and/or dependencies for deployment to AWS Lambda

Project description

Lambda Bundler

Lambda-Bundler-Build Maintainability Test Coverage PyPI version

Lambda 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 layer
  • Package code-only dependencies from multiple directories for deployment to Lambda
  • Package your own code and external dependencies into a single zip for deployment to Lambda

Dependencies will be cached if possible in order to provide a fast build experience.

Installation

The installation is very simple using pip:

pip install lambda-bundler

How to use

Package a Lambda layer

from lambda_bundler import build_layer_package

path_to_deployment_artifact = build_layer_package(
    # You can install the dependencies from multiple
    # requirement files into a single layer
    requirement_files=[
        "path/to/requirements.txt"
    ]
)

# path_to_deployment_artifact now points to a zip archive with the dependencies.

Package code directories

from lambda_bundler import build_lambda_package

path_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 archive

Package code directories and dependencies

If 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 the documentation and the content of packages larger than 3MB won't be visible in the code editor in the console.

from lambda_bundler import build_lambda_package

path_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 archive

Configuration

The library uses a working directory to build and cache packages. By default this is located in the lambda_bundler_builds folder in your temporary directory as determined by python.

If you'd like to change that, you can set the LAMBDA_BUNDLER_BUILD_DIR environment variable and point it to another directory.

Known Limitations

  • Packages 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lambda-bundler-0.0.2.tar.gz (11.9 kB view hashes)

Uploaded Source

Built Distribution

lambda_bundler-0.0.2-py3-none-any.whl (14.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page