Skip to main content

Code Climate Build Status codecov PyPI version

py-lambda-packer

A Python AWS Lambda packager. This projects is very loosely based on the work in serverless-wsgi.

NOTICE: This project is a work in progress and should be considered unstable.

Features:

  • Written to run under both Python 3.6 and 2.7.

  • Generates Python 3.6 and 2.7 AWS Lambda Deployment Packages, user configurable.

  • AWS Lambda Deployment Packages are generated in isolated, temporary virtualenvs.

  • Per project configuration files to cut down on typing.

  • Can be easily be included and integrated into other projects as a library.

Usage

Installation

Latest stable

$ pip install py-lambda-packer

Bleeding edge

To install directly the bleeding edge version from GitHub:

$ pip install git+https://github.com/digitalrounin/py-lambda-packer.git@master#egg=py-lambda-packer

To install a specific tag or branch, replace master in the URL of the previous command with the desired name.

Quick start

Quick example command to generate py-lambda-package.zip for upload to AWS as a Lambda Function

$ py-lambda-packer --requirement requirements.txt --package . \
    --python python3.6 --include LICENSE

Command help

Command help information:

$ py-lambda-packer --help

usage: py-lambda-packer [-h] [--config-file CONFIG_FILE] [--include INCLUDES]
                        [--exclude EXCLUDES] [--followlinks]
                        [--virtualenv-dir VIRTUALENV_DIR] [--keep-virtualenv]
                        [--python PYTHON] [--requirement REQUIREMENTS]
                        [--package PACKAGES] [--output OUTPUT]
                        [--archive-dir ARCHIVE_DIR] [--keep-archive]
                        [--generate-config]

optional arguments:
  -h, --help            show this help message and exit
  --config-file CONFIG_FILE
                        location of configuration file (default: ./py-lambda-
                        packer.yaml)
  --include INCLUDES    glob pattern of what to include, multiple allowed
                        (default is empty)
  --exclude EXCLUDES    glob pattern of what to exclude, multiple allowed
                        (default is empty)
  --followlinks         follows symbolic links (default=False)
  --virtualenv-dir VIRTUALENV_DIR
                        directory to build the virtualenv in (default is a tmp
                        dir)
  --keep-virtualenv     do not delete virtualenv build directory when set
                        (default=False)
  --python PYTHON       version of python to build virtualenv with (default is
                        python2.7)
  --requirement REQUIREMENTS, -r REQUIREMENTS
                        pip requirements file to read, multiple allowed
                        (default is empty)
  --package PACKAGES, -p PACKAGES
                        pip package index options, multiple allowed (default
                        is empty)
  --output OUTPUT, -o OUTPUT
                        name of output zip file (default is py-lambda-
                        packer.zip)
  --archive-dir ARCHIVE_DIR
                        directory to build the archive in (default is a tmp
                        dir)
  --keep-archive        do not delete archive build directory when set
                        (default=False)
  --generate-config     prints thedefault configuration to help create one

Project configuration

Project configuration file are named py-lambda-packer.yaml in the base directory of your project. Here is an example:

virtualenv:
  python: python2.7
  pip:
    requirements:
      - requirements.txt
    packages:
      - .
      - Flask

packager:
  target: py-lambda-package.zip
  followlinks: true
  includes:
    - LICENSE
    - static/**
    - templates/**/*.html
  excludes:
    - static/**/*.tmp

To generate a configuration file, try the py-lambda-packer --generate-config command.

Todo list

  • Bump up code coverage limit back up to 80% and fix failing source files.

  • Add comments to configuration file created by py-lambda-packer --generate-config.

  • Document the py-lambda-packer API so that it can be imported as a library into other projects.

  • Make the colorlog Python package optional to allow py-lambda-packer to be imported into other projects as a library more cleanly.

  • Plugin support.

  • Support building packages with C and C++ Python extensions. Thinking out loud… Spin up an EC2 instance on the fly via something like HashiCorp Packer, build, package, destroy instance.

  • Clean up Windows compatibility. (I do not have access to a Windows based system, so any contributions here would be greatly appreciated.)

  • Support packaging for other Function as a Service (FaaS) platforms provided by : Azure, Google Cloud, etc.

References

For more information

Metadata

Release files for py-lambda-packer 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-lambda-packer 0.1.0
File Size Uploaded
py-lambda-packer-0.1.0.tar.gz 13.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-lambda-packer 0.1.0
File Interpreter ABI Platform
py_lambda_packer-0.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 30.3 kB

Release files / py-lambda-packer-0.1.0.tar.gz

Download URL py-lambda-packer-0.1.0.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a5cdd79abab4bca660f5275a1707d3075edf71342a6845c5eddd5a45fdc4844f
BLAKE2b-256 checksum
How to use checksums
be6ffc8045721882ab1a47d8c78f6098f923019060649985abf7056b0ebf9113
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / py_lambda_packer-0.1.0-py2.py3-none-any.whl

Download URL py_lambda_packer-0.1.0-py2.py3-none-any.whl
Size 17.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
34bf4f16290e88c8855ab4d3a19b0d4380f5722e3deb7b51e99ede7b9d901803
BLAKE2b-256 checksum
How to use checksums
15d95d1a32c7e9de3c20c72a2d8a41e23ffc861a1548db30d4484273fd1a3ced
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page