AWS API Gateway
AWS API Gateway
Section titled โAWS API GatewayโAmazon API Gateway is a fully managed service for creating, publishing, and securing APIs at any scale. It acts as the โfront doorโ for backend services โ Lambda functions, EC2 instances, or any HTTP endpoint.
In Azure terms: API Gateway โ Azure API Management (APIM) + Azure API Gateway
API Types
Section titled โAPI Typesโ| Type | Description | Use Case |
|---|---|---|
| REST API | Full-featured, supports all integrations and API Gateway features | Production APIs requiring advanced features |
| HTTP API | Lightweight, lower latency, cheaper (~71% cheaper than REST API) | Simple proxy to Lambda or HTTP backends |
| WebSocket API | Persistent two-way connection between client and server | Real-time apps (chat, gaming, live dashboards) |
Core Concepts
Section titled โCore Conceptsโ| Concept | Description |
|---|---|
| Resource | A URL path (e.g., /users, /users/{id}) |
| Method | HTTP verb on a resource (GET, POST, PUT, DELETE) |
| Integration | Backend target โ Lambda, HTTP URL, AWS service, Mock |
| Stage | Deployment environment โ dev, staging, prod |
| Deployment | Snapshot of the API configuration deployed to a stage |
| Usage Plan | Throttling and quota settings |
| API Key | Client credential for usage plan access control |
| Authorizer | Lambda custom authorizer or Cognito for authentication |
| Mapping Template | Transform request/response payloads |
Typical Architecture: REST API + Lambda
Section titled โTypical Architecture: REST API + LambdaโClient (browser/app) โ HTTPS requestAPI Gateway โ proxy integrationAWS Lambda โDynamoDB / RDS / S3 โAPI Gateway โ responseClientIntegration Types
Section titled โIntegration Typesโ| Integration | Description |
|---|---|
| Lambda Proxy | Pass entire request to Lambda, return Lambdaโs response directly |
| Lambda Custom | Transform request/response with mapping templates |
| HTTP Proxy | Forward request to any HTTP endpoint |
| AWS Service | Directly invoke S3, DynamoDB, SQS, SNS etc. (no Lambda needed) |
| Mock | Return a static response without any backend call |
Security Options
Section titled โSecurity Optionsโ| Method | Description |
|---|---|
| API Keys | Simple key-based access (not for authentication โ use for quota tracking) |
| Lambda Authorizer | Custom auth logic (validate JWT, call auth service) |
| Cognito User Pools | AWS-managed OAuth2/OIDC authentication |
| IAM Authorization | SigV4-signed requests from AWS SDKs/services |
| Resource Policies | IP-based or VPC-based access restrictions |
| Mutual TLS (mTLS) | Client certificate authentication |
Throttling & Quotas
Section titled โThrottling & QuotasโAPI Gateway protects backends with built-in rate limiting:
- Account level: 10,000 requests/second (soft limit)
- Stage level: Set custom throttle limits per stage
- Usage Plans: Throttle and quota per API key
Response when throttled: 429 Too Many Requests
API Gateway vs Azure APIM
Section titled โAPI Gateway vs Azure APIMโ| Feature | AWS API Gateway | Azure API Management |
|---|---|---|
| API types | REST, HTTP, WebSocket | REST, SOAP, GraphQL, WebSocket |
| Auth | Lambda authorizer, Cognito, IAM | OAuth2, JWT, subscriptions keys, Azure AD |
| Throttling | Per stage / per usage plan | Per product / per subscription |
| Developer portal | Basic | Full-featured developer portal |
| Mock responses | Yes | Yes (via policies) |
| Transform payloads | Mapping templates | Policies (XML-based) |
| Caching | Yes (per stage) | Yes |
| Private APIs | Yes (VPC endpoint) | Internal tier |
| Pricing | Per-request + data transfer | Per-unit/hour (multi-tier) |
Canary Deployments
Section titled โCanary DeploymentsโAPI Gateway supports canary releases โ route a percentage of traffic to the new version:
# Create a deployment with canaryaws apigateway create-deployment \ --rest-api-id abc123 \ --stage-name prod \ --canary-settings \ percentTraffic=10,\ deploymentId=xyz789CLI Examples
Section titled โCLI Examplesโ# List APIsaws apigateway get-rest-apis
# Create a REST APIaws apigateway create-rest-api --name "my-api"
# Get resourcesaws apigateway get-resources --rest-api-id abc123
# Deploy to a stageaws apigateway create-deployment \ --rest-api-id abc123 \ --stage-name prod
# Get an API's stagesaws apigateway get-stages --rest-api-id abc123