API Gateway
API Gateway is the front door for your APIs: it receives HTTP requests, authenticates them and forwards them to Lambda or other backends.
On this page · 5 min · Intermediate
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Intermediate
- Updated
- Oct 29, 2026
Related tutorials
Learning objectives#
- Compare HTTP APIs and REST APIs
- Create routes with Lambda integrations
- Configure CORS and JWT authorization
- Use stages and throttling
Explanation#
HTTP APIs are simpler, cheaper and faster — the best choice for most Lambda-backed APIs. REST APIs add features such as API keys, usage plans, request validation and caching.
A route (GET /products) maps to an integration (a Lambda function, an HTTP endpoint or an AWS service).
JWT authorizers validate tokens from Amazon Cognito or any OpenID Connect provider before your code runs.
Stages (dev, prod) are deployments with their own URLs and settings; throttling protects backends from overload.
Code example: Quick-create an HTTP API in front of Lambda#
aws apigatewayv2 create-api --name products-api --protocol-type HTTP \
--target arn:aws:lambda:ap-south-1:123456789012:function:products \
--cors-configuration AllowOrigins=https://techiebabaji.com,AllowMethods=GET,POST
aws lambda add-permission --function-name products \
--statement-id apigw-invoke --action lambda:InvokeFunction \
--principal apigateway.amazonaws.com \
--source-arn "arn:aws:execute-api:ap-south-1:123456789012:<api-id>/*"
{
"ApiEndpoint": "https://<api-id>.execute-api.ap-south-1.amazonaws.com",
"ProtocolType": "HTTP"
}This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- Quick create builds an API with a default route and stage pointing to the Lambda function.
- CORS allows only your front-end origin.
- add-permission lets API Gateway invoke the function — without it requests fail with 500.
Real-world use case#
A React front end calls GET /products and POST /orders on an HTTP API; Cognito-issued JWTs protect the order routes.
Common mistakes#
API Gateway needs a resource-based permission on the function.
Allow only the origins that need access.
Best practices#
- Prefer HTTP APIs unless you need REST API features
- Use JWT authorizers for user-facing APIs
- Set throttling limits
- Enable access logging to CloudWatch
Remember this#
HTTP API = simple and cheap. REST API = more features.
Route → integration → Lambda.
API Gateway needs permission to invoke Lambda.
Practice exercise#
Your task: Add a route GET /products/{id} to an existing HTTP API integration.
Show solution
aws apigatewayv2 create-route --api-id <api-id> --route-key "GET /products/{id}" --target integrations/<integration-id>
Mini quiz#
Which API type is usually best for a simple Lambda-backed API?
Want more? Practise all AWS MCQs · AWS interview questions
My notes#
Saved in this browser.