Lambda API Decorators
Define AWS Lambda API routes and configuration directly in your Python code using decorators.
Lambda API Decorators provides Python decorators for defining API routes and AWS Lambda configuration alongside your Lambda handlers.
Instead of maintaining route and function configuration separately from your application code, you can declare HTTP methods, paths, runtimes, timeouts, memory, environment variables, layers, networking, and other Lambda settings directly on the handler.
Combined with Lambda API Decorators CDK, these definitions are used to automatically generate the corresponding AWS Lambda and Amazon API Gateway infrastructure with AWS CDK.
from lambda_api_decorators import GET, runtime, name, memory_size
import json
@GET("/dogs")
@runtime("python3.11")
@name("LBD-DOGS-GET")
@memory_size(256)
def lambda_handler(event, context):
return {
"statusCode": 200,
"body": json.dumps({
"message": "Hello World from /dogs!"
})
}
Installation
Install Lambda API Decorators from PyPI:
pip install lambda-api-decorators
To generate AWS infrastructure from the decorated Lambda handlers, install the CDK integration:
pip install lambda-api-decorators-cdk
Available Decorators
API Routes
Every Lambda API handler must define an HTTP method and endpoint path.
Available route decorators:
GETPOSTPUTDELETEANY
For example:
@GET("/dogs")
def lambda_handler(event, context):
...
The route definition is used by the CDK integration to configure the corresponding Amazon API Gateway endpoint and Lambda integration.
Lambda Configuration
Lambda API Decorators also allows Lambda configuration to be declared directly on the handler.
timeout
Defines the Lambda function timeout in seconds.
@timeout(30)
memory_size
Defines the amount of memory allocated to the Lambda function.
@memory_size(512)
name
Defines a custom name for the Lambda function.
@name("LBD-DOGS-GET")
description
Defines the Lambda function description.
@description("Returns the list of dogs")
runtime
References a runtime configuration defined by Lambda API Decorators CDK.
@runtime("python3.11")
role
References an IAM role defined by Lambda API Decorators CDK.
@role("api-role")
vpc
References a VPC configuration defined by Lambda API Decorators CDK.
@vpc("application-vpc")
environment
Associates one or more environment configurations with the Lambda function.
@environment("database", "application")
layer
Associates one or more Lambda Layers with the function.
@layer("common-dependencies")
security_group
Associates one or more security group configurations with the Lambda function.
@security_group("lambda-security-group")
The referenced runtimes, IAM roles, VPCs, environment configurations, layers, and security groups are defined in the AWS CDK application using Lambda API Decorators CDK.
How It Works
Lambda API Decorators keeps API and Lambda configuration close to the application code:
Python Lambda handlers
│
│ @GET, @POST, @runtime,
│ @timeout, @memory_size, ...
▼
Lambda API Decorators
│
▼
Lambda API Decorators CDK
│
▼
AWS CDK
│
├── AWS Lambda
├── Amazon API Gateway
├── IAM
├── VPC configuration
└── other AWS resources
This allows your Lambda handlers to become the source of the API definition while AWS CDK remains responsible for generating and deploying the infrastructure.
Related Projects
- Lambda API Decorators CDK — AWS CDK integration that generates Lambda and API Gateway infrastructure from decorated Python handlers.
- Lambda API Decorators Examples — Example applications demonstrating how to use Lambda API Decorators.
Releasing
The Git tag is the source of truth for this package's version. Maintainers create
and push a semantic-version tag from main:
git checkout main
git pull
git tag v0.2.0
git push origin v0.2.0
Pushing the tag starts the release workflow, and v0.2.0 becomes Python package
version 0.2.0. Versions in this repository are independent from
lambda-api-decorators-cdk.
Publishing uses PyPI trusted publishing. The PyPI project must have a trusted
publisher configured for this repository, the release.yml workflow, and the
pypi GitHub environment.
License
See the repository license for details.
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-0.3.0.tar.gz.
File metadata
- Download URL: lambda_api_decorators-0.3.0.tar.gz
- Upload date:
- Size: 21.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 |
5f7b4d0228543e5f5f8bab3b3e30200918da3de77e340593fc424790557e0ce3
|
|
| MD5 |
390e5670a392abdaffe2b5c15da2ea16
|
|
| BLAKE2b-256 |
72bd7d164a15dc1fdb15ab2017c3c30565800092a64cbfe68b3a89dc4d82bac8
|
Provenance
The following attestation bundles were made for lambda_api_decorators-0.3.0.tar.gz:
Publisher:
release.yml on lambda-api-decorators/lambda-api-decorators
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lambda_api_decorators-0.3.0.tar.gz -
Subject digest:
5f7b4d0228543e5f5f8bab3b3e30200918da3de77e340593fc424790557e0ce3 - Sigstore transparency entry: 2849593515
- Sigstore integration time:
-
Permalink:
lambda-api-decorators/lambda-api-decorators@28536a51b300dc191d87e0cafdc196c5dbd4e4ff -
Branch / Tag:
refs/tags/v0.3.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@28536a51b300dc191d87e0cafdc196c5dbd4e4ff -
Trigger Event:
push
-
Statement type:
File details
Details for the file lambda_api_decorators-0.3.0-py3-none-any.whl.
File metadata
- Download URL: lambda_api_decorators-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.5 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 |
b877c971d4cecfabd7edbabf5371b8d709745fa02d6bf8681cc0942fcf000011
|
|
| MD5 |
41206cc89446605b29a6b1c59d6eec6b
|
|
| BLAKE2b-256 |
a2441c3a0bc494a40396fd485e0052e3283e763e9918a933822461911c099103
|
Provenance
The following attestation bundles were made for lambda_api_decorators-0.3.0-py3-none-any.whl:
Publisher:
release.yml on lambda-api-decorators/lambda-api-decorators
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lambda_api_decorators-0.3.0-py3-none-any.whl -
Subject digest:
b877c971d4cecfabd7edbabf5371b8d709745fa02d6bf8681cc0942fcf000011 - Sigstore transparency entry: 2849593580
- Sigstore integration time:
-
Permalink:
lambda-api-decorators/lambda-api-decorators@28536a51b300dc191d87e0cafdc196c5dbd4e4ff -
Branch / Tag:
refs/tags/v0.3.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@28536a51b300dc191d87e0cafdc196c5dbd4e4ff -
Trigger Event:
push
-
Statement type: