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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lambda_api_decorators_cdk-0.4.0.tar.gz.
File metadata
- Download URL: lambda_api_decorators_cdk-0.4.0.tar.gz
- Upload date:
- Size: 54.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2eb1613cdc530d7bf8db81f270d51277c125c536da73789a37daf028831a4596
|
|
| MD5 |
377814da13f681ec2559465339c6c490
|
|
| BLAKE2b-256 |
0194387334b93d4018c9106b24287f7ddd354db51f15d091a338911661b2138d
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lambda_api_decorators_cdk-0.4.0.tar.gz -
Subject digest:
2eb1613cdc530d7bf8db81f270d51277c125c536da73789a37daf028831a4596 - Sigstore transparency entry: 2849520712
- Sigstore integration time:
-
Permalink:
lambda-api-decorators/lambda-api-decorators-cdk@3fbca58ba36e8115f2c66ea9a95a34bebba16615 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/lambda-api-decorators
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3fbca58ba36e8115f2c66ea9a95a34bebba16615 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lambda_api_decorators_cdk-0.4.0-py3-none-any.whl.
File metadata
- Download URL: lambda_api_decorators_cdk-0.4.0-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3090287484838a0af278eb01915ec54d94782992068ee0c26c793343e3b286f8
|
|
| MD5 |
1b9cb40c54dd5309b1d604d6f0db6ab6
|
|
| BLAKE2b-256 |
282071e97e06cdf02c9a5d60771bb8602f8dadd09ed8aa913e8ef473fe77375a
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lambda_api_decorators_cdk-0.4.0-py3-none-any.whl -
Subject digest:
3090287484838a0af278eb01915ec54d94782992068ee0c26c793343e3b286f8 - Sigstore transparency entry: 2849520866
- Sigstore integration time:
-
Permalink:
lambda-api-decorators/lambda-api-decorators-cdk@3fbca58ba36e8115f2c66ea9a95a34bebba16615 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/lambda-api-decorators
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3fbca58ba36e8115f2c66ea9a95a34bebba16615 -
Trigger Event:
push
-
Statement type: