Skip to content
Back to Cloud Services

AWS API Gateway

Managed API gateway with REST/HTTP/WebSocket APIs, throttling, auth, and Lambda/HTTP integration.

AWSIntermediate

Why

API Gateway handles auth, throttling, caching, and API keys — offloading cross-cutting concerns. HTTP API is 70% cheaper than REST API. 1M requests/mo free for 12 months.

When

Use for public APIs needing auth/throttling, Lambda frontends, and WebSocket. Avoid for internal APIs (use ALB) or gRPC (use ALB with gRPC support).

How

1. Choose type — REST (full features), HTTP (cheaper, simpler), WebSocket 2. Routes — /users/{id} → Lambda/HTTP integration 3. Auth — Cognito, Lambda authorizer, IAM, or JWT (HTTP API) 4. Throttling — rate limit + burst, per-key via usage plans 5. Stages — dev/staging/prod, deploy via aws apigateway create-deployment 6. Custom domain — ACM cert, base path mapping 7. Logging — CloudWatch Logs, access logs, execution logs 8. OpenAPI — import/export spec, generate SDK

Example

# HTTP API with Lambda proxy aws apigatewayv2 create-api \ --name my-api \ --protocol-type HTTP \ --target arn:aws:lambda:us-east-1:123:function:my-fn # OpenAPI spec import aws apigateway import-rest-api \ --body file://openapi.yaml \ --mode overwrite # Stage with throttling aws apigateway create-deployment \ --rest-api-id abc123 \ --stage-name prod \ --stage-description "throttle: 1000 rps, burst 2000"

Common Problems

  • ⚠REST API expensive — HTTP API 70% cheaper, use unless you need REST-specific features
  • ⚠429 throttling — increase burst/rate, or use usage plans per customer
  • ⚠Cold start with Lambda — first request slow, provisioned concurrency fixes it

Best Practices

  • ✓Use HTTP API over REST — 70% cheaper, covers most use cases
  • ✓Enable caching for read-heavy — $0.02/hr per GB, cuts Lambda invocations 90%
  • ✓Use usage plans for B2B — per-customer throttling, quota, API keys

FAQ

What is AWS API Gateway and what problem does it solve?

Managed API gateway with REST/HTTP/WebSocket APIs, throttling, auth, and Lambda/HTTP integration. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with AWS API Gateway in 5 minutes?

Two steps to run it: (1) Choose type — REST (full features), HTTP (cheaper, simpler), WebSocket; (2) Routes — /users/{id} → Lambda/HTTP integration. Validate on the free tier first, then wire into production.

What is the #1 pitfall with AWS API Gateway?

The most frequent issue is: REST API expensive — HTTP API 70% cheaper, use unless you need REST-specific features. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for AWS API Gateway?

Best practices for AWS API Gateway include: Use HTTP API over REST — 70% cheaper, covers most use cases; Enable caching for read-heavy — $0.02/hr per GB, cuts Lambda invocations 90%; Use usage plans for B2B — per-customer throttling, quota, API keys. The first one — "Use HTTP API over REST — 70% cheaper, covers most use cases" — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with AWS API Gateway?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most AWS API Gateway options offer a free tier — validate within free quota before scaling.