Ravi Sir's Cards › AWS › API Gateway
Amazon API Gateway: HTTP vs REST vs WebSocket, routes, CORS and stages
This page keeps the API Gateway cards on one topic page. It has the ten cards from “What is Amazon API Gateway? REST vs HTTP vs WebSocket” and the ten cards from “Build a REST API with API Gateway and Lambda step by step”.
Each card still has its image and its original text. Under each group you will also find a short Why, What, How example, and an exam tip, in easy English. The names, paths, domains and request limits in the stories are made up for learning. Prices mentioned on the cards can change — check current AWS pricing when you practise.
What is API Gateway, and which type to pick
Why this matters
Browsers should not hold AWS credentials or invent routing. A raw Lambda Function URL can be fine for a simple private tool, but a public app usually needs a real front door.
What it is
API Gateway is the HTTPS front door: routes, auth, throttle, and stages. A route is a method plus a path, such as GET /notes. A stage is a named deployment (dev or prod) with its own URL and settings, so those environments do not share one URL by accident. HTTP APIs are cheaper and simpler for Lambda and HTTP proxy work (the live comparison card cites about $1 per million requests in the first tier — always re-check official pricing). REST APIs add API management features such as API keys, usage plans, WAF, and private APIs. REST or HTTP APIs are one request and one response. A WebSocket API keeps a long-lived connection, with routes such as $connect and $disconnect, and you must track connection ids for push updates. Lambda proxy integration means Gateway passes the HTTP request to Lambda, and you return statusCode, headers, and body.
How it works — a real example
Suppose a static site calls fetch(API+"/hello") and hits an HTTP API, which then invokes Lambda. A student notes lab uses an HTTP API. A partner API that needs keys uses a REST API. A teacher’s live quiz uses a WebSocket API to push an update to open student connections. Dev stays on a private stage; students use the prod stage URL. The names are made up for learning.
Common mistake / exam tip
Default a new serverless JSON API to HTTP API unless you need REST-only features such as API keys, WAF, or a private API. Do not put a public SPA on Lambda Function URLs forever — you lose rich routing, usage plans, and central auth. Deploy to prod only after you test on dev.
Why API Gateway in front of Lambda
Read card text
What this card says
Why do we need it?
Browsers should not hold AWS credentials or invent routing.
What is it?
API Gateway is the HTTPS front door: routes, auth, throttle, stages.
How to do it
Create an HTTP API, add a route, integrate Lambda, copy the invoke URL. https://xxxx.execute-api…
Example
fetch(API+"/hello") from a static site hits Gateway, then Lambda.
HTTP API vs REST API
Read card text
What this card says
Why do we need it?
Two product names confuse new teams. Pick for features and price.
What is it?
HTTP APIs are cheaper/simpler for Lambda proxies. REST APIs add API keys, WAF, private APIs.
How to do it
Default new serverless JSON API → HTTP API unless you need REST-only features.
Example
Student notes lab uses HTTP API. Partner API with keys uses REST.
When to use WebSocket APIs
Read card text
What this card says
Why do we need it?
Chat and live boards need push, not one-shot request/response.
What is it?
WebSocket APIs keep a connection; Gateway routes $connect, $disconnect, messages.
How to do it
Create WebSocket API → integrate Lambda on routes → manage connection ids. $connect
Example
Teacher pushes a quiz update to all open student connections.
Routes, methods and stages
Read card text
What this card says
Why do we need it?
Dev and prod must not share one URL by accident.
What is it?
Route = method + path. Stage = named deployment (dev/prod) with settings.
How to do it
Add GET /notes and POST /notes; deploy to $default or prod. GET /notes
Example
prod stage URL goes to students; dev stays private.
Comparison: Default choice?
Read card text
What this card says
HTTP API
Cheaper, simpler Lambda/HTTP proxy.
REST API
More API management features.
Key points
JWT, CORS, routes. API keys, usage plans, WAF, private APIs.
Example
~$1 / million requests (first tier).
Use when
Most new serverless JSON APIs. Keys, WAF or private API needs.
Comparison: Connection style
Read card text
What this card says
REST/HTTP API
One request, one response.
WebSocket API
Long-lived push connection.
Key points
Stateless per call. Track connection ids.
Example
CRUD notes API.
Use when
Standard web APIs. Real-time updates.
Interview: Why not call Lambda Function URLs from a public SPA forever?
Read card text
What this card says
What it is
You lose rich routing, usage plans and central auth patterns.
Why it matters
API Gateway (or CloudFront+auth) is the usual public front door.
How / example
Use Function URLs for simple private tools; public apps prefer Gateway.
Interview: What is Lambda proxy integration?
Read card text
What this card says
What it is
Gateway passes the HTTP request to Lambda; you return statusCode, headers, body.
Why it matters
One pattern for almost all serverless REST/HTTP handlers.
How / example
return {statusCode:200, headers:{…}, body: JSON.stringify(x)}.
Interview: When do you pick HTTP API over REST?
Read card text
What this card says
What it is
Lambda/HTTP proxy, CORS, JWT — without API keys/WAF/private API needs.
Why it matters
Lower price and simpler config for most student and startup APIs.
How / example
Need API keys + usage plans → REST instead.
Interview: What is an API stage?
Read card text
What this card says
What it is
A named snapshot/deployment of the API with its own URL and settings.
Why it matters
Lets you separate dev traffic from prod.
How / example
Deploy to prod only after testing on dev.
Build a REST or HTTP API: CORS, parameters, keys and domains
Why this matters
curl can work while the browser blocks the call. Students then think the API is down. And a long execute-api URL looks temporary on a project you want to share.
What it is
Browsers enforce the Same-Origin Policy. Cross-origin calls need Access-Control-Allow-* headers. Some calls first send an OPTIONS preflight; if OPTIONS fails, the real POST never leaves the browser. Enable CORS on the HTTP API, and for proxy integrations also return Allow-Origin from Lambda. Path parameters such as /notes/{id} and query strings such as ?limit=10 appear in the event; read event.pathParameters.id in the function. REST APIs can require an API key (x-api-key) and a usage plan: a throttle is a short rate (requests per second), and a quota is a longer budget (for example per day). Excess can return 429. After you change method settings on a REST API, you must redeploy to the stage or clients still see the old config. A custom domain with an ACM certificate gives https://api.yourdomain.com. For a regional API, the certificate is in the same Region. A proxy Lambda must return statusCode, headers, and a body that is usually a JSON string.
How it works — a real example
Suppose the UI is on CloudFront and the API is on execute-api — the origins differ, so CORS is required. DELETE /notes/abc-123 reads the path id and deletes that item. A partner key is limited to 10 requests per second and 100,000 per day. Students later hit api.school.com/notes instead of a long execute-api URL. The names and limits are made up for learning, except where a card states a lab figure.
Common mistake / exam tip
CORS is not the same as authorization. CORS lets a browser from another origin call you; IAM, JWT, a Lambda authorizer, or API keys decide who is allowed. If you forget to JSON.stringify the proxy body, the client sees a bad payload. After REST method changes, use Actions, Deploy API, and choose the stage.
Why browsers need CORS
Read card text
What this card says
Why do we need it?
curl works; the browser blocks. Students think the API is down.
What is it?
Same-Origin Policy. Cross-origin calls need Access-Control-Allow-* headers.
How to do it
Enable CORS on the HTTP API; return Allow-Origin in Lambda too for proxy. Access-Control-Allow-Origin
Example
UI on CloudFront, API on execute-api → both origins differ → CORS required.
Path and query parameters
Read card text
What this card says
Why do we need it?
Hard-coded ids do not scale. Routes must carry resource ids.
What is it?
Path params: /notes/{id}. Query: /notes?limit=10. Both appear in the event.
How to do it
Define {id} in the route; read event.pathParameters.id in Lambda. /notes/{id}
Example
DELETE /notes/abc-123 deletes that item.
API keys, plans and throttle
Read card text
What this card says
Why do we need it?
Public anonymous floods burn free tier. Partners need quotas.
What is it?
REST APIs: API keys + usage plans set quota and throttle (req/s).
How to do it
Create key → usage plan → attach stage → require key on methods → redeploy. x-api-key
Example
Partner gets 10 req/s and 100k/day; excess returns 429.
Custom domain with ACM
Read card text
What this card says
Why do we need it?
execute-api URLs look temporary on a résumé project.
What is it?
Custom domain + ACM certificate gives https://api.yourdomain.com.
How to do it
Regional API: cert in the same region. Map domain to the stage. api.example.com
Example
Students hit api.school.com/notes instead of long execute-api URLs.
Comparison: Problem solved
Read card text
What this card says
CORS
Browser cross-origin access.
API authorization
Who is allowed to call the API.
Key points
Access-Control-Allow-* headers. IAM, JWT, Lambda authorizer, API keys.
Example
Static site on another domain.
Use when
Enable so the UI can call. Enable so only the right callers succeed.
Comparison: Time window
Read card text
What this card says
Throttle
Short rate limit (requests per second).
Quota
Longer budget (e.g. per day).
Key points
Stops sudden floods. Caps total monthly/daily use.
Example
10 req/s burst.
Use when
Protect Lambda concurrency. Protect free-tier / partner plans.
Interview: What is a CORS preflight?
Read card text
What this card says
What it is
Browser OPTIONS request before some cross-origin calls.
Why it matters
Server must answer Allow-Methods and Allow-Headers.
How / example
If OPTIONS fails, the real POST never leaves the browser.
Interview: Throttle vs quota?
Read card text
What this card says
What it is
Throttle = short rate (req/s burst). Quota = longer budget (e.g. per day).
Why it matters
Both protect backends and your bill.
How / example
10 req/s throttle, 50,000/day quota on a student plan.
Interview: After changing method settings on REST, what next?
Read card text
What this card says
What it is
Redeploy the API to the stage or clients still see old config.
Why it matters
Settings are not live until deployed.
How / example
Actions › Deploy API › choose stage.
Interview: What must a proxy Lambda return?
Read card text
What this card says
What it is
statusCode, headers, body (usually a JSON string).
Why it matters
Gateway maps that object to a real HTTP response.
How / example
Forgot to JSON.stringify body → client sees a bad payload.
FAQ
Why put API Gateway in front of Lambda?
It is the HTTPS front door: routes, auth, throttle, and stages. Browsers should not hold AWS credentials or invent routing.
When should I pick an HTTP API instead of a REST API?
These cards say to default new serverless JSON APIs to HTTP API for a cheaper, simpler Lambda or HTTP proxy, with CORS and JWT. Pick REST when you need API keys, usage plans, WAF, or a private API. Re-check current pricing.
When do I need a WebSocket API?
When clients need a long-lived push connection, such as chat or a live board. You manage $connect, $disconnect, and connection ids. Ordinary CRUD can stay on REST or HTTP.
What is Lambda proxy integration?
Gateway passes the HTTP request to Lambda. You return statusCode, headers, and body (usually a JSON string). That object becomes the real HTTP response.
What is an API stage?
A named snapshot or deployment of the API, with its own URL and settings, so dev traffic can stay separate from prod.
Why does curl work but the browser fail?
The browser enforces the Same-Origin Policy. Cross-origin calls need CORS headers. Some calls first send an OPTIONS preflight; if OPTIONS fails, the real request never leaves the browser.
What is the difference between throttle and quota?
Throttle is a short rate limit (requests per second). Quota is a longer budget, such as per day. Both protect the backend and your bill. Excess can return 429.
After I change a REST API method, why is nothing different?
You must redeploy the API to the stage. Settings are not live until you deploy. For a friendly URL, map a custom domain with an ACM certificate in the same Region as a regional API.
Related lessons
These chapter pages are already on the site (checked live, HTTP 200, on 19 Nov 2026):