Generally, we receive the HTTP 504 errors from Gateway REST API when we invoke it using Amazon API Gateway.
Here, at Bobcares, we assist our customers with several AWS queries as part of our AWS Support Services.
Today, let us see how our techs troubleshoot the error.
HTTP 504 errors from Gateway REST API
API Gateway returns this error if an integration takes longer than the API Gateway REST API maximum integration timeout parameter
To troubleshoot this, first, we need to identify and verify the source of the error in the Amazon CloudWatch execution logs.
Then, we have to reduce the runtime of the integration requests until they don’t timeout.
Moving ahead, let us see how our Support Techs perform them.
Identify and verify the source in Amazon CloudWatch logs
1. Initially, we configure API Gateway logging for the API that returns the errors.
2. Then we go ahead and manually reproduce the 504 error.
3. In the CloudWatch console, we view the API Gateway execution logs for the integration receiving the error.
4. Later, we track the request ID in the CloudWatch logs.
In the case of timeouts, below the “Endpoint request body after transformations:” line, we’ll see an Execution failed due to a timeout error message.
5. To determine the source of the error, we:
a) Verify that the associating integration endpoint was invoked.
b) Confirm how long the integration logic took to complete and respond to API Gateway.
6. Suppose there was no invoke. Then we retry the request.
In this case, the error might be the result of a temporary network failure in the API Gateway service.
On the other hand, suppose the integration was invoked but returns a 504 error message.
In such a case, we either increase the maximum integration request timeout parameter or reduce the integration’s runtime.
Reduce the integration’s runtime
First, we need to make sure that the backend integration includes only the logic for API Gateway to send an HTTP response to the client.
If not, we move any nondependent or post-processing logic to another service.
In case the error is due to network latencies, we implement retry logic on the client-side application.
If we follow the optimization best practices for the platform, we can improve the backend integration.
If none of these actions helps, we consider implementing asynchronous API Gateway integration calls.
[Need further assistance? We are here to assist you]
In short, we saw how our Support Techs troubleshoot HTTP 504 errors from Gateway REST API.