- Newest
- Most votes
- Most comments
This is not a bug but limitation on API Gateway handling caching, the behavior you're experiencing with API Gateway caching 500 errors from a Lambda authorizer is a recognized limitation when utilizing authorization caching. API Gateway indiscriminately caches all responses from the authorizer, including error responses, which may result in the issue you've observed.
Please consider:
- Return 401 or 403 instead of 500
- Disable Caching Temporarily
- Reduce Cache TTL
- Custom your own Error handling
This is a very insightful observation, and you're absolutely right that the current behavior of API Gateway caching any response from a Lambda authorizer — including transient 500s — can cause significant issues in production environments. While this is not technically a bug, it is a serious limitation in the design.
Since there is no way for the authorizer to signal "do not cache this response", and the cache indiscriminately stores even failure results, we're left in a position where the architecture must be reconsidered for fault-tolerance and resilience.
Instead of offering a single definitive solution, here are a few directions you might consider — each with trade-offs — depending on what flexibility you have in your system design:
Option 1: Disable caching or set authorizerResultTtlInSeconds
to 0
- This avoids the caching issue altogether.
- Downside: every request will trigger a Lambda execution, which may impact latency and cost.
- Reference: API Gateway Lambda Authorizer Caching
Option 2: Use a JWT authorizer (e.g., Cognito or OIDC)
- If you're issuing JWTs, consider configuring an Amazon Cognito authorizer or a generic JWT authorizer.
- These perform verification directly in API Gateway — no Lambda function is involved.
- This avoids the issue of authorizer Lambda failures being cached, because there's no Lambda execution to fail.
Option 3: Separate authentication and authorization logic
- Let API Gateway handle authentication (via JWT verification or Cognito), and move fine-grained authorization checks to your backend services.
- This decouples transient infrastructure issues (e.g., DB connectivity) from the authentication phase, which is where the caching issue arises.
Relevant content
- asked 7 months ago
None of those options work.