Learn/Labs
Labs · 18 min read · August 2026
Serverless API Lab: API Gateway + Lambda
HTTP API in front of Lambda the way AWS documents it — integration, IAM invoke, stages, and the checks before you call it shipped.
Source. Amazon API Gateway Developer Guide · Lambda permissions · HTTP APIs
Abstract & theoretical context
API Gateway is the front door. HTTP APIs (v2) are the simpler, cheaper path AWS recommends for most new REST-ish backends. A route maps METHOD /path to a Lambda integration. Gateway needs lambda:InvokeFunction on your execution role relationship — usually via a resource-based policy on the function. Stages, throttling, and access logs are how a campus demo stops being an open proxy. This lab follows the official HTTP API + Lambda path, not a screenshot-only wizard click-through.
Models, formulas & variables
1. Request path
Client → HTTP API (TLS) → Lambda integration → function → JSON response
- — Payload format 2.0 is the HTTP API default. Do not parse REST API v1 events by accident.
- — Authorizers (JWT/IAM) come after the happy path works.
2. Invoke permission
Gateway service principal + source ARN → lambda:InvokeFunction on the function ARN
- — If you see 500 with no logs, it is often missing invoke permission, not your Python.
- — One function per route is fine for labs; later, one function with a router is a style choice.
Reference implementation
Copy into a sandbox account. Pin Region ap-south-1 unless the lab says otherwise.
http-api-event.json
API Gateway HTTP API payload 2.0
{
"version": "2.0",
"routeKey": "GET /hello",
"rawPath": "/hello",
"queryStringParameters": { "name": "tcet" },
"requestContext": {
"http": { "method": "GET", "path": "/hello" }
}
}Lab procedure
- 01Create the Python handler from the compute article and deploy it with a least-privilege execution role (logs only).
- 02Create an HTTP API, add GET /hello → Lambda proxy integration.
- 03Add the resource-based invoke permission (console does this if you use the integration wizard — verify in Lambda → Permissions).
- 04Enable access logs to CloudWatch. Hit the default endpoint. Confirm 200 and a request id.
- 05Add a usage plan / throttle for the stage. Delete the API at the end of the session.
Key insights
- REST APIs (v1) still exist. Prefer HTTP APIs unless you need API keys, WAF mappings, or legacy features.
- CORS is a gateway configuration, not a wish in the Lambda return body alone.
- Never return secrets in the JSON body. Structured logs belong in CloudWatch, not in the client.
Account & lab requirements
lambda:CreateFunction, apigateway permissions, CloudWatch Logs. Tear down HTTP APIs so default endpoints do not linger.
More in Labs
CloudWatch: Logs, Metrics, and One Alarm That Matters
How AWS documents observability: log groups, namespaces, and alarms — enough to know a Lambda is broken without SSHing anywhere.
AWS CDK Starter: One Stack, One Bucket, No Click-Ops
Infrastructure as code the way AWS documents CDK: app, stack, construct, synth, deploy — starting with a locked-down S3 bucket.