Skip to main content

HTTP decorators

GET, POST, PUT, DELETE, and ANY have the signature DECORATOR(path) and return a decorator that preserves the callable. path is a non-empty literal path when discovered by CDK.

GET​

PUT​

POST​

DELETE​

ANY​

Each handler declares exactly one HTTP route. Applying a second HTTP decorator raises ValueError, for example: Lambda handler 'handler' declares multiple routes: GET /first, POST /second. Each handler must declare exactly one HTTP route. The error prevents one Lambda handler from silently representing multiple route declarations.

Valid handlers are separate functions:

from lambda_api_decorators import GET, POST

@GET("/orders")
def list_orders(event, context):
return {"statusCode": 200, "body": "[]"}

@POST("/orders")
def create_order(event, context):
return {"statusCode": 201, "body": "created"}

Invalid:

from lambda_api_decorators import GET, POST

@GET("/orders")
@POST("/orders")
def invalid(event, context):
return {"statusCode": 200, "body": "never built"}

ANY(path) is a public REST route decorator. The HTTP API builder supports GET, POST, PUT, and DELETE; use an explicit method for an HTTP API.