What is Amazon API Gateway and when would you use it?
Amazon API Gateway is a managed front door for your APIs — handling routing, authorization, throttling, and caching. Learn its API types and key use cases.
Expected Interview Answer
Amazon API Gateway is a fully managed service for creating, publishing, securing, and monitoring APIs at scale, acting as the front door that routes client requests to backends like Lambda, EC2, or other AWS services.
It handles the cross-cutting concerns of an API so backends don't have to: request routing, authorization (IAM, Cognito, Lambda authorizers), throttling and rate limiting, caching, request/response transformation, and usage plans with API keys. It offers REST APIs (feature-rich), HTTP APIs (cheaper, lower latency), and WebSocket APIs (real-time). You use it to expose serverless functions as HTTP endpoints, build public or partner APIs, and centralize auth, monitoring, and traffic management.
- Fully managed — no servers to run for the API layer
- Built-in authorization, throttling, and rate limiting
- Scales automatically to handle traffic spikes
- Caching reduces backend load and latency
- Centralizes monitoring, logging, and versioning
- Supports REST, HTTP, and WebSocket APIs
AI Mentor Explanation
API Gateway is like the stadium's main entrance managing every spectator: it checks tickets before entry (authorization), controls how fast the crowd flows through the gates (throttling), directs each fan to the right stand (routing to backends), and counts attendance for the board (monitoring). The players inside never deal with the queue at the gate.
Step-by-Step Explanation
Step 1
Define the API
Choose REST, HTTP, or WebSocket and declare resources, routes, and methods that clients will call.
Step 2
Integrate backends
Map each route to a backend such as Lambda, an HTTP endpoint, or another AWS service integration.
Step 3
Add authorization
Secure routes with IAM, Cognito user pools, or Lambda authorizers, plus API keys and usage plans.
Step 4
Configure traffic controls
Set throttling, rate limits, and caching to protect backends and reduce latency.
Step 5
Deploy and monitor
Deploy to a stage, enable CloudWatch logging and metrics, and version the API as it evolves.
What Interviewer Expects
- Defines API Gateway as a managed API front door
- Names backends it routes to (Lambda, EC2, AWS services)
- Explains built-in auth, throttling, and caching
- Distinguishes REST, HTTP, and WebSocket API types
- Gives realistic use cases like serverless APIs
Common Mistakes
- Confusing API Gateway with a load balancer
- Not knowing the difference between REST and HTTP APIs
- Forgetting throttling and usage plans exist
- Assuming it stores data or runs business logic itself
- Overlooking caching to reduce backend load
Best Answer (HR Friendly)
“Amazon API Gateway is a managed service that acts as the front door for your APIs. It receives requests from apps, checks that they are allowed in, controls how much traffic gets through, and passes each request to the right backend, so your developers don't have to build all that plumbing themselves.”
Code Example
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
GetItemsApi:
Type: AWS::Serverless::HttpApi
Properties:
StageName: prod
GetItemsFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs20.x
Events:
GetItems:
Type: HttpApi
Properties:
ApiId: !Ref GetItemsApi
Path: /items
Method: GETFollow-up Questions
- What is the difference between REST APIs and HTTP APIs in API Gateway?
- How do Lambda authorizers work compared to Cognito authorizers?
- When would you enable caching on an API Gateway stage?
- How do usage plans and API keys throttle individual clients?
MCQ Practice
1. Which is a core responsibility of Amazon API Gateway?
API Gateway handles cross-cutting API concerns such as authorization, throttling, and routing to backends, not data storage or compute logic itself.
2. Which API Gateway type is best for a real-time chat feature needing persistent connections?
WebSocket APIs maintain persistent bidirectional connections, ideal for real-time features like chat or live updates.
3. Why might you choose an HTTP API over a REST API in API Gateway?
HTTP APIs are cheaper and faster than REST APIs, trading some advanced features for cost and latency benefits.
Flash Cards
What is Amazon API Gateway? — A managed service to create, publish, secure, and monitor APIs that route client requests to backends like Lambda and EC2.
Which API types does it support? — REST APIs (feature-rich), HTTP APIs (cheaper, lower latency), and WebSocket APIs (real-time bidirectional).
How does it protect backends? — With throttling, rate limiting, usage plans, caching, and authorization via IAM, Cognito, or Lambda authorizers.
When is a WebSocket API right? — For real-time, persistent, bidirectional communication such as chat, notifications, or live dashboards.