Skip to main content

REST and HTTP APIs

If this is your first deployment, start with Getting Started. That tutorial creates a REST API using the default behavior of LambdaApi. For complete runnable projects, see the Quickstart REST example and HTTP API example.

REST is the default​

When api_type is omitted and no API is supplied, LambdaApi creates an apigateway.RestApi. The following is the explicit REST form; it creates the same API family as the default:

from aws_cdk import Stack, aws_lambda as lambda_
from constructs import Construct
from lambda_api_decorators_cdk import ApiType, LambdaApi, LambdaApiConfig


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

self.api = LambdaApi(
self,
"Api",
lambda_path="lambdas",
api_type=ApiType.REST,
config=LambdaApiConfig(default_runtime="python3.14"),
)

REST routes can be declared with GET, POST, PUT, DELETE, or ANY. ANY is passed through by the REST builder. Each handler must declare exactly one route; use separate handlers for separate methods. See the HTTP decorator reference.

Explicit HTTP API​

Set api_type=ApiType.HTTP to make LambdaApi create an apigatewayv2.HttpApi instead:

from aws_cdk import Stack, aws_lambda as lambda_
from constructs import Construct
from lambda_api_decorators_cdk import ApiType, LambdaApi, LambdaApiConfig


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

self.api = LambdaApi(
self,
"Api",
lambda_path="lambdas",
api_type=ApiType.HTTP,
config=LambdaApiConfig(default_runtime="python3.14"),
)

The current HTTP builder maps GET, POST, PUT, and DELETE to HTTP API routes. ANY is part of the public decorator set, but it has no HTTP mapping and therefore cannot be used with an HTTP LambdaApi. The current discovery and builder code does not expose additional route decorators through this construct. These are the behavior differences relevant to this package; this page is not a general API Gateway comparison.

Both variants use lambda_path to discover decorated top-level Python functions and create Lambda integrations. The API family is selected by ApiType, whose public values are documented in the types reference.