- Newest
- Most votes
- Most comments
My understanding is: The behavior you are seeing is expected because AWS service-level throttling (due to Concurrency Limits) occurs before your Lambda code is even invoked. Since the Lambda doesn't execute, it cannot return the required JSON object for the Proxy Integration, causing API Gateway to default to a 500 Internal Server Error.
To solve this without leaving Proxy Integration, you should configure Gateway Responses in API Gateway:
- Gateway Response Types: Specifically, you need to customize the
DEFAULT_429(for API Gateway level throttling) and potentiallyDEFAULT_5XX(if the integration fails to reach Lambda due to service limits). - Implementation: In the API Gateway Console, go to Gateway Responses. You can map these responses to return a
429status code and manually add thex-amzn-ErrorType:TooManyRequestsException header. - This acts as a "catch-all" at the API Gateway level for cases where the Lambda cannot be reached or fails to respond correctly, satisfying your requirement for a production-safe workaround in proxy mode.
This ensures the client receives the correct status code even when your Lambda function never starts.
- https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway-errors.html
- https://docs.aws.amazon.com/apigateway/latest/developerguide/supported-gateway-response-types.html
Look for the following log sequence:
- Integration Request Error: You will likely see Execution failed due to configuration error or Execution failed due to limit exceeded.
- Early Exit: If the log shows the execution failing immediately after the "Method Request" stage and before the "Method Response" stage, it confirms that API Gateway is generating the 500 error itself because it couldn't successfully invoke the Lambda.
In these specific scenarios, Gateway Responses (specifically DEFAULT_5XX or THROTTLED) are the only way to intercept and re-map the status code back to a 429 for the client.
When using Lambda proxy integration with API Gateway, Lambda is required to return output in a specific format that includes a statusCode property and optionally a headers property. API Gateway will map the Lambda response to an HTTP response based on the statusCode you specify in the Lambda function's return value.
For API Gateway to properly pass error types like throttling (429) to clients in proxy integration mode, your Lambda function must return the error in the correct format. The response should include:
- A
statusCodeset to the appropriate HTTP status code (e.g., 429 for throttling) - A
headersproperty that can include error type information (e.g.,"X-Amzn-ErrorType":"TooManyRequestsException")
If you're seeing a 500 error instead of a 429, this suggests the Lambda function may not be returning the response in the expected proxy integration format. When Lambda itself is being throttled by AWS (due to concurrency limits), this is a service-level throttle that occurs before your function code executes, which may not follow the standard proxy integration response format.
The behavior you're describing—where Lambda throttling results in a 500 error—is likely because the throttling is happening at the Lambda service level rather than being handled within your function code. In proxy integration mode, API Gateway expects a properly formatted response from your Lambda function, but service-level throttles may not provide this format.
To work around this limitation while staying in proxy mode, you would need to implement throttling logic within your Lambda function code itself, allowing you to return a properly formatted 429 response. However, this doesn't address AWS service-level concurrency throttles.
For distinguishing between different error types at the client level, ensure your Lambda function returns responses with appropriate status codes and custom headers when errors occur within your application logic.
Sources
Handle Lambda errors in API Gateway - Amazon API Gateway
Relevant content
- asked 2 years ago

I’m facing the same issue as the original poster and am hoping for the same solution.
When I tested your suggestion, it appeared that Lambda’s
TooManyRequestsExceptionis mapped toDEFAULT_5XXrather thanDEFAULT_429in API Gateway. As I understand it, if we remapDEFAULT_5XXto 429, the 5XX errors that Lambda returns when it runs normally will also become 429s. Does this mean it’s not possible to set it to 429 only when Lambda returns a 500 and the response header includesx-amzn-ErrorType: TooManyRequestsException?I look forward to your response.