Skip to main content

Quickstart HTTP API

The http-api project is a standalone CDK application with one GET /hello route backed by API Gateway HTTP API.

It is an independent application, not a second stack in quickstart-rest.

Architecture​

The CDK app creates one HttpApiStack, one Python 3.14 Lambda function, one HTTP API, one GET /hello route, and its AWS proxy integration. It does not create a REST API.

What changes from Quickstart REST?​

The handler shape is the same, but LambdaApi receives api_type=ApiType.HTTP. The generated API resources are AWS::ApiGatewayV2 rather than AWS::ApiGateway. The stack also exposes a HttpApiEndpoint output, and the handler returns Hello from HTTP API!.

Infrastructure​

The complete http_api/http_api_stack.py is:

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


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

config = LambdaApiConfig(
runtime=lambda_.Runtime.PYTHON_3_14,
)

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

CfnOutput(self, "HttpApiEndpoint", value=api.api.api_endpoint)

ApiType.HTTP selects the HTTP API builder. HttpApiEndpoint is the deployment output used to call the route.

Lambda handler​

The complete lambdas/hello.py is:

import json

from lambda_api_decorators import GET


@GET("/hello")
def lambda_handler(event, context):
return {
"statusCode": 200,
"headers": {"Content-Type": "application/json"},
"body": json.dumps({"message": "Hello from HTTP API!"}),
}

@GET("/hello") becomes the single HTTP API route, and the proxy response body contains Hello from HTTP API!.

Main files and tests​

http-api/
├── app.py
├── cdk.json
├── requirements.txt
├── requirements-dev.txt
├── http_api/
│ └── http_api_stack.py
├── lambdas/
│ ├── __init__.py
│ ├── hello.py
│ └── requirements.txt
└── tests/
├── test_hello.py
└── test_stack.py

test_hello.py checks the proxy response. test_stack.py verifies the HTTP protocol, GET /hello route, AWS proxy integration, Lambda runtime, and absence of a REST API.

note

Docker must be running for the infrastructure test and cdk synth, because CDK packages the Python Lambda with PythonFunction.

Run the project​

Run these commands from http-api.

python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements-dev.txt
pytest -q
cdk synth --quiet
cdk bootstrap
cdk deploy
caution

Run cdk bootstrap and cdk deploy only with the intended AWS account and credentials configured.

Test the API​

Copy the HttpApiEndpoint output after deployment and append /hello:

curl "https://YOUR_HTTP_API_ID.execute-api.YOUR_REGION.amazonaws.com/hello"

Clean up​

cdk destroy

Complete source​

See the complete http-api directory for the runnable project and its README.