Skip to content

Docker images for bundling Python packages into AWS Lambda layers using pip syntax

License

Notifications You must be signed in to change notification settings

lyngon/lambda-pip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lambda Pip

Facilitates adding Python dependencies to AWS Lambda layers when using AWS CDK

Example:

class Stack(aws_cdk.Stack):
    def __init__(
        self, scope: constructs.Construct, construct_id: str, **kwargs
    ) -> None:
        super().__init__(scope, construct_id, **kwargs)

        py_ver = aws_cdk.aws_lambda.Runtime.PYTHON_3_9

        # Install requirements in a Lambda Layer
        dependency_layer = aws_cdk.aws_lambda.LayerVersion(
            self,
            "my-lambda-dependency-layer",
            code=aws_cdk.aws_lambda.Code.from_asset(
                ".",
                bundling=aws_cdk.BundlingOptions(
                    image=aws_cdk.DockerImage.from_registry(
                        f"lyngon/lambda-pip:{py_ver.name}"
                    ),
                    command=["-r", "requirements.txt"],
                ),
            ),
        )

        # Lambda Function, with the layer
        my_lambda = aws_cdk.aws_lambda.Function(
            self,
            "my-lambda",
            runtime=py_ver,
            code=aws_cdk.aws_lambda.Code.from_asset("src/aws/lambda"),
            handler="my_lambda.entrypoint",
            layers=[dependency_layer],
        )

Building

docker build -t lyngon/lambda-pip:python3.9 src

Or for a specific version of python (here 3.8)

docker build --build-arg py=3.8 -t lyngon/lambda-pip:python3.8 src

About

Docker images for bundling Python packages into AWS Lambda layers using pip syntax

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published