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 License PythonVersions

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.

If you're using the Cloud Development Kit and just want to do a cdk synth to check your infrastructure code without actually deploying it, you can set the environment variable LAMBDA_BUNDLER_SKIP_INSTALL to true. 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 to true.

Demo / Example

For an example of how to use this, I suggest you check out the demo repository which includes a CDK app that deploys three lambda functions with dependencies of different sizes. If you take a closer look at the build pipeline you'll see, how effective the caching is.

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.1.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lambda_bundler-0.1.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file lambda-bundler-0.1.0.tar.gz.

File metadata

  • Download URL: lambda-bundler-0.1.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for lambda-bundler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ff6acc3ddfda507dd27017d289acdb7099736a6b14e7aa730d4699dec58e8b61
MD5 216d2242e547bec0187dd978fad2135f
BLAKE2b-256 06ab8d1f110ba47b74dfdb3b3218ea27e092fffc967fae3cb1d7cd5799ced608

See more details on using hashes here.

File details

Details for the file lambda_bundler-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lambda_bundler-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for lambda_bundler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 227cc98e7927ebffc9da707be4cc833b296adeeb81fc18e451615de30194eef3
MD5 ac1656ffc91aed01881a105207c58402
BLAKE2b-256 e7c4cdd5f268954a82b143babd883bd79c525c84e34d74f63c184da4b8a8c24a

See more details on using hashes here.

Supported by

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