Skip to main content

Poetry Plugin Lambda Build

The plugin for poetry that allows you to build zip packages suited for serverless deployment like AWS Lambda, Google App Engine, Azure App Service, and more...

Additionally it provides docker container support for build inside container

Test

Installation

poetry self add poetry-plugin-lambda-build

Execution

Configure pyproject.toml with the following configuration. This is example for AWS Lambda configuration

[tool.poetry-plugin-lambda-build]
docker-image = "public.ecr.aws/sam/build-python3.11:latest-x86_64"
docker-network = "host"
layer-artifact-path = "artifacts/layer.zip"
layer-install-dir = "python"
function-artifact-path = "artifacts/function.zip"

Running ...

poetry build-lambda

will build function and layer packages for AWS Lambda deployment inside public.ecr.aws/sam/build-python3.11:latest-x86_64 container.

artifacts
├── function.zip
└── layer.zip

Running ...

poetry build-lambda docker-image="public.ecr.aws/sam/build-python3.12:latest-x86_64"

will override docker-image value in config

Configuration Examples

AWS Lambda - all in one - dependencies and function in the same zip package - Default

[tool.poetry-plugin-lambda-build]
package-artifact-path = "package.zip"

AWS Lambda - all in one - layer package

[tool.poetry-plugin-lambda-build]
package-install-dir = "python"
package-artifact-path = "layer.zip"

AWS Lambda - separated - separate layer package and function package

[tool.poetry-plugin-lambda-build]
layer-artifact-path = "layer.zip"
layer-install-dir = "python"
function-artifact-path = "function.zip"

AWS Lambda - separated - separate layer package and function package build in docker container

[tool.poetry-plugin-lambda-build]
docker-image = "public.ecr.aws/sam/build-python3.11:latest-x86_64"
docker-network = "host"
layer-artifact-path = "layer.zip"
layer-install-dir = "python"
function-artifact-path = "function.zip"

Help

poetry build-lambda help
Description:
  Execute to build lambda lambda artifacts

Usage:
  build-lambda [options] [--] [<docker-image> [<docker-entrypoint> [<docker-environment> [<docker-dns> [<docker-network> [<docker-network-mode> [<docker-platform> [<package-artifact-path> [<package-install-dir> [<function-artifact-path> [<function-install-dir> [<layer-artifact-path> [<layer-install-dir> [<only> [<without> [<with> [<zip-compresslevel> [<zip-compression> [<pre-install-script> [<dockerignore> [<dockerignore-file>]]]]]]]]]]]]]]]]]]]]]

Arguments:
  docker-image                   The image to run
  docker-entrypoint              The entrypoint for the container (comma separated string) [default: "/bin/bash"]
  docker-environment             Environment variables to set inside the container (comma separated string) ex. VAR_1=VALUE_1,VAR_2=VALUE_2
  docker-dns                     Set custom DNS servers (comma separated string)
  docker-network                 The name of the network this container will be connected to at creation time [default: "host"]
  docker-network-mode            Network-mode
  docker-platform                Platform in the format os[/arch[/variant]]. Only used if the method needs to pull the requested image.
  package-artifact-path          Output package path (default: package.zip). Set the '.zip' extension to wrap the artifact into a zip package otherwise, output will be created in the directory. [default: "package.zip"]
  package-install-dir            Installation directory inside artifact for single package [default: ""]
  function-artifact-path         Output function package path. Set the '.zip' extension to wrap the artifact into a zip package otherwise, output will be created in the directory.
  function-install-dir           Installation directory inside artifact for function package [default: ""]
  layer-artifact-path            Output layer package path. Set the '.zip' extension to wrap the artifact into a zip package otherwise, output will be created in the directory.
  layer-install-dir              Installation directory inside artifact for layer package [default: ""]
  only                           The only dependency groups to include
  without                        The dependency groups to ignore
  with                           The optional dependency groups to include
  zip-compresslevel              None (default for the given compression type) or an integer specifying the level to pass to the compressor. When using ZIP_STORED or ZIP_LZMA this keyword has no effect. When using ZIP_DEFLATED integers 0 through 9 are accepted. When using ZIP_BZIP2 integers 1 through 9 are accepted.
  zip-compression                ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib), ZIP_BZIP2 (requires bz2) or ZIP_LZMA (requires lzma) [default: "ZIP_STORED"]
  pre-install-script             The script that is executed before installation.
  dockerignore                   Comma-separated list of patterns to ignore when copying files to container
  dockerignore-file              Path to a .dockerignore file to use for filtering files

Options:
      --no-checksum              Enable to suppress checksum checking
      --docker-network-disabled  Disable networking
  -h, --help                 Display help for the given command. When no command is given display help for the list command.
  -q, --quiet                Do not output any message.
  -V, --version              Display this application version.
      --ansi                 Force ANSI output.
      --no-ansi              Disable ANSI output.
  -n, --no-interaction       Do not ask any interactive question.
      --no-plugins           Disables plugins.
      --no-cache             Disables Poetry source caches.
  -C, --directory=DIRECTORY  The working directory for the Poetry command (defaults to the current working directory).
  -v|vv|vvv, --verbose       Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.

Tips

Mac users with Docker Desktops

Make sure to configure DOCKER_HOST properly

export DOCKER_HOST=unix:///Users/$USER/.docker/run/docker.sock

Metadata

Release files for poetry-plugin-lambda-build 2.1.2

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

Source distribution (sdist)

Source distribution for poetry-plugin-lambda-build 2.1.2
File Size Uploaded
poetry_plugin_lambda_build-2.1.2.tar.gz 17.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for poetry-plugin-lambda-build 2.1.2
File Interpreter ABI Platform
poetry_plugin_lambda_build-2.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 38.2 kB

Release files / poetry_plugin_lambda_build-2.1.2.tar.gz

Download URL poetry_plugin_lambda_build-2.1.2.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
240fb77c872dae3b0adcebab41c7a69038f2d5a7fbc05f52d285c12347a068c9
BLAKE2b-256 checksum
How to use checksums
caee137dded002bf99a51c7f98fc3199bc2730542cc4f71e202cf67e3cf490d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.9 Linux/6.11.0-1018-azure

Release files / poetry_plugin_lambda_build-2.1.2-py3-none-any.whl

Download URL poetry_plugin_lambda_build-2.1.2-py3-none-any.whl
Size 20.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3f1d2b1c18477660b7c6f02f41061d6ace652f4f61755b748be30c46636413b
BLAKE2b-256 checksum
How to use checksums
adf086d7e4db6a5a17fdd7417583f6072ee6032ee5f488b26414a6f8d903f5b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.9 Linux/6.11.0-1018-azure

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.6.4

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.5

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

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