Skip to main content

Enables building AWS Lambda Layers from requirement files as part of CDK deployments

Project description

layer-builder

Simple library that supports building AWS Lambda layers as part of your AWS CDK build process. Cross-platform (supports both Win and Mac), targeting both x86 and ARM chips, and based on you existing requirements.txt.

Build from requirements

Using this library, you can build a layer containing the packages defined in a requirements.txt file in your AWS CDK pipeline (or other tools). The packages are installed in a local directory using the appropriate platform target.

Wherever possible we attempt to limit the size of the resulting layer by removing any packages that are already native to Lambda (boto, six, future, etc.) or otherwise unnecessary. additional_commands and cleanup_function parameters can be used to further reduce the size of the package by removing any unnecessary libraries.

from layer_builder import build_from_requirements
from constructs import Construct
from aws_cdk import Stack, aws_lambda as aws_lambda

class LayerStack(Stack):

    def __init__(
        self,
        scope: Construct,
        construct_id: str,
        **kwargs,
    ) -> None:
        super().__init__(scope, construct_id, **kwargs)
        
        build_from_requirements(
            "../../requirements.txt", # The packages to install
            "./build/layer", # Where to place the layer packages
            max_mb=20, # Check if the size of the layer is larger than expected
            clean=True, # Delete previous install
            graviton=True, # Specify targeting ARM architecture
        )
        self.my_layer = aws_lambda.LayerVersion(
            self,
            "my-layer",
            compatible_runtimes=[aws_lambda.Runtime.PYTHON_3_13],
            compatible_architectures=[aws_lambda.Architecture.ARM_64],
            code=aws_lambda.Code.from_asset("./build/layer"),
        )

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

layer_builder-0.1.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

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

layer_builder-0.1.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file layer_builder-0.1.1.tar.gz.

File metadata

  • Download URL: layer_builder-0.1.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.13.5 Windows/11

File hashes

Hashes for layer_builder-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bd8fbde3a285f95d08fd628e618cb05dc2736864a96be89a9ec8e7c7da5bddf4
MD5 132b01615e34cf950420050d6644211d
BLAKE2b-256 426f71d736308b6b52d279292b7f2404e9bb868006deeea35d813ae826983ea6

See more details on using hashes here.

File details

Details for the file layer_builder-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: layer_builder-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.13.5 Windows/11

File hashes

Hashes for layer_builder-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da36053d9e0b70c7ba91cf9ebef3dec2c18776ae7f70756e4d982a31c818489e
MD5 8b075474ece639a99fd3da580f6ad930
BLAKE2b-256 50c15c04daa7eafb5dbe6655ce10190366c828658f3e8fbe50fe814922977a82

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