Amazon API Gateway

On this page 7

Amazon API Gateway is a fully managed AWS service for creating, publishing, securing and operating HTTP, REST and WebSocket APIs at any scale. In serverless architectures within the Cloud, it acts as the front door that accepts client requests, authenticates them, applies throttling and transformation rules, and forwards them to a backend such as AWS Lambda, a container service, another AWS service or any public HTTP endpoint.

Because the service is billed per request and scales without capacity planning, it pairs naturally with function-based backends: an application can expose dozens of endpoints without running a single server or load balancer, and the cost falls close to zero when traffic stops.

How Amazon API Gateway processes a request

Amazon API Gateway processes each call through a fixed request pipeline that runs before and after the backend is reached. A client sends an HTTPS request to a stage endpoint, the gateway matches it to a resource and method (or a route in HTTP APIs), runs authorization, validates and optionally transforms the payload, and then invokes the configured integration.

The response travels back through the same pipeline, where the gateway can map status codes, rewrite headers and cache the result. The main stages of this flow are summarized below.

StageWhat happensTypical configuration
Endpoint and routingRequest is matched to a route or resource and methodPath such as /orders/{id} with GET
AuthorizationCaller identity is verifiedIAM, Cognito user pool, JWT or Lambda authorizer
Throttling and quotasRate and burst limits are enforcedAccount, stage, method or usage plan limits
Request validationBody and parameters are checkedJSON Schema models, required headers
IntegrationBackend is invokedLambda proxy, HTTP proxy, AWS service, mock
Response mappingOutput is shaped and optionally cachedMapping templates, cache TTL
Stages of the request pipeline

Two integration styles dominate. In a proxy integration, the gateway passes the entire request to the backend and returns its response unchanged, which keeps logic in code. In a non-proxy integration, Velocity Template Language mapping templates reshape requests and responses inside the gateway, which allows direct calls to services such as DynamoDB or Step Functions without any intermediate function.

API types: REST, HTTP and WebSocket

Amazon API Gateway offers three API types that differ in features, latency and price, and choosing among them is the first design decision. REST APIs are the original, feature-rich option; HTTP APIs are a leaner, cheaper and lower-latency product; WebSocket APIs maintain persistent two-way connections for real-time messaging.

CapabilityREST APIHTTP APIWebSocket API
Relative price per million requestsHighestRoughly 70 percent lowerBilled per message and connection minute
Usage plans and API keysYesNoNo
Response cachingYesNoNo
Request validation and transformationFull mapping templatesLimited parameter mappingRoute selection expressions
Native JWT authorizerThrough Cognito or LambdaYesThrough Lambda
Private endpoint typeYesNoNo
Typical usePublic or partner APIs with governanceSimple Lambda or container backendsChat, live dashboards, notifications
Comparison of the three API types

REST APIs also come in three endpoint types: edge-optimized, which routes traffic through the CloudFront network for geographically spread clients; regional, which serves clients in the same region or behind a custom CDN; and private, which is reachable only from inside a VPC through an interface endpoint.

Security, throttling and operational limits

Security in Amazon API Gateway rests on layered controls: authentication at the gateway, network restrictions through resource policies and optional AWS WAF rules, and encryption in transit through TLS. Mutual TLS can be required on custom domain names when clients present certificates.

Throttling uses a token bucket algorithm with a steady-state rate and a burst capacity. By default, an account receives about 10,000 requests per second with a burst of 5,000 per region, although these defaults can be raised on request and vary by region. Exceeding a limit returns HTTP 429 Too Many Requests, which clients should handle with exponential backoff.

Several hard or soft limits shape architecture decisions and are often discovered late in a project.

LimitTypical valueDesign consequence
Integration timeout29 seconds by defaultLong jobs need asynchronous patterns
Payload size10 MB per requestLarge uploads should use presigned S3 URLs
WebSocket message frame32 KB per frameLarge messages must be split
WebSocket connection duration2 hours maximumClients must reconnect periodically
Cache size0.5 GB to 237 GBChosen per stage; billed hourly
Limits that commonly affect design

How it relates to neighboring serverless services

Amazon API Gateway is an ingress and API management layer, not a compute service, so it is usually combined with others rather than compared directly. Its closest alternatives are other ways of exposing an HTTP endpoint for a function or container.

OptionStrengthWeakness
Amazon API GatewayAuthorization, throttling, keys, transformationPer-request cost, 29-second default timeout
Lambda function URLSimplest single endpoint, no extra chargeNo usage plans, caching or routing
Application Load BalancerCheaper at sustained high trafficHourly charge even when idle, fewer API features
Amazon CloudFront with Lambda@EdgeGlobal edge executionRestricted runtime and payload limits
Ways to expose a backend over HTTP on AWS

Event-driven designs often place the gateway at the edge and hand off work to Amazon EventBridge, SQS or Step Functions, so that the client receives a quick acknowledgment while processing continues asynchronously. Infrastructure is commonly defined with AWS SAM, the Serverless Framework or CloudFormation, which keeps routes, authorizers and stages under version control.

Common mistakes and how to avoid them

Most production incidents with Amazon API Gateway come from misread limits and missing observability, not from the service itself. The following list collects frequent errors seen in practice.

  • Choosing REST APIs by habit when an HTTP API covers every requirement at a fraction of the cost.
  • Running synchronous long tasks that exceed the integration timeout instead of returning a job identifier.
  • Treating API keys as authentication; they identify usage plan customers but do not prove identity.
  • Ignoring cold start latency of Lambda backends; provisioned concurrency or lighter runtimes help latency-sensitive routes.
  • Leaving access logging disabled, which makes 4xx and 5xx spikes hard to diagnose; structured logs and CloudWatch metrics such as Latency and IntegrationLatency should be enabled per stage.

Explained without jargon

Think of Amazon API Gateway as the reception desk of an office building. Visitors, which are apps and websites, arrive with requests. The desk checks who they are, refuses anyone without a valid badge, limits how many people come in at once, and sends each visitor to the right department.

The departments behind the desk can be small programs that start only when needed. Because the desk is run by Amazon, the business never hires staff for it or worries about crowds. It pays only for the visitors who actually come in.

A typical use case

A regional food delivery startup builds its mobile ordering backend on AWS. The team creates an HTTP API with routes such as POST /orders and GET /orders/{id}, uses a JWT authorizer connected to its Cognito user pool, and sends each route to a separate Lambda function written in Python.

Placing an order writes to DynamoDB and publishes an event to EventBridge, which triggers restaurant notification and courier assignment asynchronously, so the API responds in about 150 milliseconds. A stage throttle of 200 requests per second protects the database during lunch peaks.

With roughly 3 million requests per month, the gateway costs only a few dollars, there are no servers to patch, and traffic that triples on holidays is absorbed without any capacity changes.