Skip to main content

No project description provided

Project description

Python 3.10 Python 3.11 Python 3.12 Code style: black

CDK-Klayers

Use Klayers within your CDK Stacks.

Install

pip install cdk-klayers

Usage (short version)

Simply use the Klayers Class within your CDK Stack. You will need to specify a runtime and region for it to work.

from cdk_klayers import Klayers

class MockStack(Stack):

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

        runtime = aws_lambda.Runtime.PYTHON_3_12

        # Initialize Klayers 
        klayers = Klayers(
            self,
            python_version = runtime
            region = "ap-southeast-1"
        )
    
        # get the latest layer version for the requests package
        requests_layer = klayers.layer_version(self, "requests")

        lambda_function = aws_lambda.Function(
            self, 'HelloHandler',
            runtime=runtime,
            layers=[requests_layer],
            code=aws_lambda.Code.from_asset('lambda'),
            hand

Usage (long version)

This example shows a fully working CDK stack that deploys a single lambda function with 2 layers from Klayers. The region of the stack was inferred from the CDK Environment.

from aws_cdk import aws_lambda
from aws_cdk import App, Environment, Stack
from aws_cdk import Aws
from constructs import Construct

from cdk_klayers import Klayers

class MockStack(Stack):

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

        runtime = aws_lambda.Runtime.PYTHON_3_12

        # Initialize Klayers 
        klayers = Klayers(
            self,
            python_version = runtime
        )
    
        # get the latest layer version for the requests package
        requests_layer = klayers.layer_version(self, "requests")
        idna_layer = klayers.layer_version(self, "idna", layer_version="2")

        lambda_function = aws_lambda.Function(
            self, 'HelloHandler',
            runtime=runtime,
            layers=[requests_layer, idna_layer],
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler'
        )


app = App()
env = Environment(region="us-east-1")
mock_stack =MockStack(app, "test", env=env)

Other Notes

We're still in beta, this might change. Please raise an issue if you have any feedback.

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

cdk_klayers-0.3.0.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

cdk_klayers-0.3.0-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

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