Difficulty: Intermediate
What is Amazon API Gateway, what does it handle for you, and how do REST APIs, HTTP APIs, and WebSocket APIs differ?
Amazon API Gateway is a fully managed service that acts as the front door for your APIs: it receives HTTP or WebSocket requests, authenticates and throttles them, optionally validates or transforms them, and forwards them to a backend such as Lambda, an HTTP service, or another AWS service. It handles TLS, scaling, rate limiting, and monitoring, which is why it is the standard way to expose serverless backends. It comes in three flavours: REST APIs (most features), HTTP APIs (simpler, cheaper, lower latency), and WebSocket APIs (two-way real-time connections).
429 Too Many Requests.| Feature | REST API | HTTP API | WebSocket API |
|---|---|---|---|
| Typical use | Public APIs needing full control | Most Lambda or HTTP backends | Chat, live dashboards, notifications |
| Auth | IAM, Cognito, Lambda authorizer, API keys | IAM, JWT (Cognito, Auth0), Lambda authorizer | IAM, Lambda authorizer on connect |
| Usage plans and API keys | Yes | No | No |
| Response caching | Yes | No | No |
| Request validation, mapping templates | Yes | Limited parameter mapping | Route selection expressions |
| AWS WAF | Yes | No (put CloudFront with WAF in front) | No |
| Endpoint types | Edge-optimised, Regional, Private | Regional | Regional |
| Price | Higher | Significantly lower | Per message and connection minute |
Rule of thumb: start with an HTTP API, and move to a REST API only if you need a feature it lacks (usage plans for API keys, caching, WAF, private endpoints, request validation).
202).statusCode, headers, body as a string), or clients see a 502 Bad Gateway.Resources:
OrdersApi:
Type: AWS::Serverless::HttpApi
Properties:
Auth:
DefaultAuthorizer: CognitoJwt
Authorizers:
CognitoJwt:
IdentitySource: $request.header.Authorization
JwtConfiguration:
issuer: https://cognito-idp.ap-south-1.amazonaws.com/ap-south-1_AbCdEf123
audience: [3n4b5urk1ft4fl3mg5e62d9ado]
DefaultRouteSettings:
ThrottlingRateLimit: 200
ThrottlingBurstLimit: 400
CreateOrderFn:
Type: AWS::Serverless::Function
Properties:
Runtime: python3.13
Handler: app.handler
CodeUri: src/
Events:
CreateOrder:
Type: HttpApi
Properties:
ApiId: !Ref OrdersApi
Path: /orders
Method: POST
API Gateway validates the Cognito JWT and enforces rate limits before invoking the Lambda function, so the function only handles authenticated, throttled traffic.
Amazon API Gateway, REST vs HTTP APIs, Throttling, Authorizers, Lambda Proxy Integration