- Newest
- Most votes
- Most comments
The behavior you're observing is related to how API Gateway handles gateway responses and their default configurations. Let me explain what's happening:
API Gateway provides gateway response types that can be customized, including INTEGRATION_FAILURE and DEFAULT_5XX. The INTEGRATION_FAILURE response type has a default status code of 504, while DEFAULT_5XX serves as a fallback gateway response for unspecified 5XX response types with a null default status code.
When all Response fields are set to their default values (uncustomized state), API Gateway may return a 500 status code because the DEFAULT_5XX gateway response is being used as the fallback. This fallback has a null status code by default, which can result in a 500 error being returned.
When you customize the "Integration failure" gateway response with a custom status code, API Gateway starts using the INTEGRATION_FAILURE response type explicitly, which has a default status code of 504. This is why you see the 504 error after making the customization, even without redeploying.
When you delete the custom response, the system reverts to using the DEFAULT_5XX fallback behavior again, which explains why you see the 500 status code return.
To answer your specific questions:
- A 500 error can occur in "default mode" when the
DEFAULT_5XXfallback response is being used - A 504 error occurs when the
INTEGRATION_FAILUREgateway response type is explicitly configured or triggered, as 504 is its default status code
The key insight is that changing the status code of DEFAULT_5XX affects all other 5XX responses, and resetting it to null reverts other 5XX responses to their original values. This explains the consistency behavior you're experiencing - the system is working as designed, switching between the specific INTEGRATION_FAILURE response type (504) and the general DEFAULT_5XX fallback (500) based on your configuration.
Sources
Gateway response types for API Gateway - Amazon API Gateway
Direct Answers
-
Can a 500 occur with a custom
Integration failureresponse?
Yes, if the error is not an integration failure (e.g., Lambda code error, timeout, or API configuration error) and you haven’t customizedDEFAULT_5XX. -
Can a 504 occur with default Gateway Responses?
Yes – the default status forIntegration failureis504.
If you saw500in default mode, the error was likely a different 5XX (e.g., Lambda unhandled exception). A true concurrency throttle isIntegration failure→ default504.
Why You Saw Inconsistent Responses
- First request (500) – Probably a Lambda invocation error (e.g., cold start bug, not a throttle).
- After customizing
Integration failureto 504 – A real throttle now returns your custom 504. - After deleting custom response – API Gateway falls back to default
504forIntegration failure. If you see500again, the error type changed back to a generic 5XX (check Lambda logs).
How to Make It Consistent (CLI / Console)
✅ Via Console
- Go to API Gateway → your API → Gateway Responses.
- Edit
Integration failure→ set status code to503or429(recommended for throttles). - Edit
DEFAULT_5XX→ set status code to500(or your preferred fallback). - Redeploy the API.
✅ Via CLI
# Get response ID for Integration failure aws apigateway get-gateway-responses --rest-api-id <api-id> # Update Integration failure to return 429 (custom body optional) aws apigateway update-gateway-response \ --rest-api-id <api-id> \ --response-type INTEGRATION_FAILURE \ --patch-operations op=replace,path=/statusCode,value='429' # Redeploy aws apigateway create-deployment --rest-api-id <api-id> --stage-name <stage>
Relevant content
- asked a year ago
- asked 2 years ago
