⭐⭐⭐⭐ Strongly Emphasized

🚦 API Gateway Monitoring

API Gateway is the front door to your backend services. Monitoring it properly helps you understand API performance, cache effectiveness, error rates, and diagnose exactly where latency originates — in the API Gateway layer or the backend.

🔑 Covers: Latency vs IntegrationLatency · Cache Metrics · Error Rates · Access Logs · CloudWatch Integration

⏱️ The Most Important Metrics — Latency Deep Dive

Understanding the difference between Latency and IntegrationLatency is one of the most frequently tested API Gateway concepts.

API Gateway Request Flow — Where Time is Spent
📱ClientSends request
⏱️API GW ProcessingAuth, throttle check, transform
🔗Backend CallLambda / HTTP / Mock
⏱️API GW ProcessingResponse transform, cache store
📱ClientGets response
←——————————————— Latency (total time) ———————————————→
                     ←————— IntegrationLatency (backend time) —————→

⏱️ Latency

Definition: Total time from when API Gateway receives the request to when it sends the response to the client.

Includes: All API Gateway processing + time waiting for backend + response processing.

Measures: The end-to-end response time as experienced by the client.

High Latency Signal: Investigate both API Gateway overhead AND backend performance.

🔗 IntegrationLatency

Definition: Time from when API Gateway sends the request to the backend until it receives the response from the backend.

Includes: Only the backend processing time (Lambda execution, HTTP endpoint response time).

Does NOT include: API Gateway's own processing overhead.

High IntegrationLatency: Backend (Lambda, HTTP) is slow. Focus optimization there.

🧮 The Math — What It Tells You

API Gateway Overhead = Latency − IntegrationLatency

If Latency = 500ms and IntegrationLatency = 480ms → API GW overhead = 20ms (normal). Backend is the problem.

If Latency = 500ms and IntegrationLatency = 50ms → API GW overhead = 450ms (abnormal!). Problem is inside API Gateway — check: authorizer, WAF, request transformation, VPC Link latency.

🎯 Critical Exam Pattern
"Latency is high but IntegrationLatency is low" → The bottleneck is INSIDE API Gateway, not in the backend. Possible causes: Lambda authorizer is slow, request/response mapping templates are complex, WAF is adding latency, VPC Link has connectivity issues.

"Latency is high AND IntegrationLatency is high" → Backend (Lambda/HTTP) is slow. Optimize your Lambda function or backend API.

💾 API Gateway Cache Metrics

API Gateway can cache backend responses for a configurable TTL. Cache metrics tell you how effectively your cache is working.

✅ CacheHitCount

Number of requests served from the API Gateway cache (no backend call made). High hit count = cache is working = lower cost + lower latency + less load on backend.

Goal: High as possible for cacheable endpoints.

❌ CacheMissCount

Number of requests that couldn't be served from cache (backend was called). Could be because: cache is disabled, TTL expired, request has unique parameters, cache was invalidated.

High Miss Count means: Review TTL settings, check what's making requests uncacheable (query parameters, headers).

📊 Cache Hit Rate Calculation

Cache Hit Rate = CacheHitCount / (CacheHitCount + CacheMissCount) × 100%

A good cache hit rate is 70-90%+. If it's low, consider: increasing TTL, removing dynamic parameters from cache key, enabling caching for more methods.

💡 API Gateway Cache Configuration
Cache must be enabled per stage. Configure TTL (default 300 seconds), cache capacity (0.5GB to 237GB), and which query string parameters/headers to use as cache keys. Only GET and HEAD requests are cached by default (POST can be configured but is unusual).

📝 Access Logs — Detailed Request Logging

By default, API Gateway only sends metrics to CloudWatch. To get detailed logs of each API request/response, you enable Access Logging.

What Access Logs Contain

You define the log format using context variables. Example fields you can log:

API Gateway — Access Log Format { "requestId": "$context.requestId", "ip": "$context.identity.sourceIp", "requestTime": "$context.requestTime", "httpMethod": "$context.httpMethod", "routeKey": "$context.routeKey", "status": "$context.status", "protocol": "$context.protocol", "responseLength": "$context.responseLength", "integrationLatency": "$context.integrationLatency", "responseLatency": "$context.responseLatency", "userAgent": "$context.identity.userAgent" }

Access logs go to a CloudWatch Logs Group. You can then use Logs Insights to query them and build dashboards.

📊 Other Key API Gateway Metrics

🔢
Count
Total number of API requests in a given period
⚠️
4XXError
Client errors (bad request, auth failed, not found). Problem is in the client request.
🔴
5XXError
Server errors (Lambda timeout, backend failure). Problem is in your backend.
🔒
ThrottleCount
Requests throttled due to rate/burst limits being exceeded.