AWS TCET

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. 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. 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

  1. 01Create the Python handler from the compute article and deploy it with a least-privilege execution role (logs only).
  2. 02Create an HTTP API, add GET /hello → Lambda proxy integration.
  3. 03Add the resource-based invoke permission (console does this if you use the integration wizard — verify in Lambda → Permissions).
  4. 04Enable access logs to CloudWatch. Hit the default endpoint. Confirm 200 and a request id.
  5. 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