Skip to main content

Lambda API Decorators CDK

A library for AWS API Gateway/Lambda Proxy Integration

Lambda API Decorators CDK allows simplified resource creation for AWS Lambda functions and Rest API resources by using decorators and setting a builder with default, common or custom values for IAM Roles, Runtimes, Timeouts, Layers, Environment values, etc. This project relies abstract syntactic trees (ast) to analyze the code of your lambda functions and generate infraestructure accordingly.

Installation

lambda_api_decorators_cdk is available from PyPI as lambda-api-decorators-cdk:

pip install lambda-api-decorators-cdk

Installation of lambda-api-decorators is also required as a dependency for your lambda functions, since it provides the definition of decorators used within this module.

Example

    import lambda_api_decorators_cdk
    or
    from lambda_api_decorators_cdk import ResourceBuilder

Builder instance

You may define a builder using lambda_api_decorators_cdk's constructor ResourceBuilder. This method returns an instance of the class that will be used to configure and create your Lambda Functions. By default, no parameters are required to instantiate the object, but custom options may be passed in advanced use cases.

    from lambda_api_decorators_cdk import ResourceBuilder

    builder = ResourceBuilder()

Builder Configuration

If opted to, you can set default values for IAM Roles, Memory Size, Timeout, Runtime and VPC.

On the same note, support for common configuration that all the Lambda Functions will receive, such as Security Groups, Environment variables and Layers, is provided.

Lastly you can setup custom environments, layers, security groups, vpcs a Lambda Function will receive ONLY if they have the decorators defined.

    from lambda_api_decorators_cdk import ResourceBuilder
    from aws_cdk import Duration

    builder = ResourceBuilder()
    builder.set_default_timeout(Duration.seconds(30))
    builder.add_common_environment("DATABASE_URI", "something-db-related")
    builder.add_custom_environment("URL-PREFIX", "lambda-api-decorators-cdk-") #Lambda Function should have decorator @environment("URL-PREFIX")

Building

Assuming you have already instantiated a Builder, configured it and ready to deploy your stack, then simply define the directory of your Lambda Functions and build!

Note: For a Lambda Function to be recognised and built, it has to have a decorator specifying the HTTP method it responds to. Decorators are defined in the lambda-api-decorators package.

[...] # Imports

class LambdaApiDecoratorsExampleStack(Stack):

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

        [...]  # Instantiating builder, defining options and layers...

        lambda_path = 'lambdas'

        restapi = apigateway.RestApi(
            self, 'lambda-api-decorators-RestApi',
            rest_api_name= 'lambda-api-decorators-restApi')
        root_resource = restapi.root

        builder.build(self, root_resource, lambda_path, print_tree=True)

Maintainer releases

The Git tag is the single source of truth for this package's version. For example, v0.3.0 produces Python package version 0.3.0. This repository is versioned independently from lambda-api-decorators.

To release from main, choose and push a semantic version tag:

git checkout main
git pull

git tag v0.3.0
git push origin v0.3.0

Pushing the tag triggers the release workflow, which tests, builds, verifies the version, and publishes with PyPI trusted publishing. The PyPI project must have a trusted publisher configured for this repository, the release.yml workflow, and the pypi GitHub environment.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lambda_api_decorators_cdk-0.4.0.tar.gz (54.3 kB view details)

Uploaded Source

Built Distribution

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

lambda_api_decorators_cdk-0.4.0-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file lambda_api_decorators_cdk-0.4.0.tar.gz.

File metadata

File hashes

Hashes for lambda_api_decorators_cdk-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2eb1613cdc530d7bf8db81f270d51277c125c536da73789a37daf028831a4596
MD5 377814da13f681ec2559465339c6c490
BLAKE2b-256 0194387334b93d4018c9106b24287f7ddd354db51f15d091a338911661b2138d

See more details on using hashes here.

Provenance

The following attestation bundles were made for lambda_api_decorators_cdk-0.4.0.tar.gz:

Publisher: release.yml on lambda-api-decorators/lambda-api-decorators-cdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lambda_api_decorators_cdk-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lambda_api_decorators_cdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3090287484838a0af278eb01915ec54d94782992068ee0c26c793343e3b286f8
MD5 1b9cb40c54dd5309b1d604d6f0db6ab6
BLAKE2b-256 282071e97e06cdf02c9a5d60771bb8602f8dadd09ed8aa913e8ef473fe77375a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lambda_api_decorators_cdk-0.4.0-py3-none-any.whl:

Publisher: release.yml on lambda-api-decorators/lambda-api-decorators-cdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 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