Amazon API Gateway 504: Execution failed due to a timeout error

As per the documentation, For Rest APIs 29 seconds Integration timeout limit is a hard limit which means it can’t be increased. For HTTP APIs the Integration timeout limit is 30 seconds

LAMBDA INTEGRATION

Workaround:
You can asynchronously Invoke your backend to return a HTTP 202 status code which means that the request has been accepted for processing, but the processing has not been completed. At client end, You can implement a polling logic to call another API resource/method to check the status of task running in the backend.

If you are having a Lambda Integration for your API, asynchronously invoking lambda just needs X-Amz-Invocation-Type to be sent as value Event in Integration Request.

More details on setting up asynchronous invocation of the backend Lambda function can be found here – https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-integration-async.html

HTTP INTEGRATION

Unlike Lambda Integration, HTTP Integration does not have option of passing X-Amz-Invocation-Type header to asynchronously Invoke. In this case the HTTP Integration has to ensure that response is returned within API Gateway Timeout configured in Integration request.

Alternatively, client can make a call to trigger the request and return immediately and later trigger another API call to check for the status of the request.

client —> API Gateway —> HTTP Endpoint (Request A returned wit 202 status )
client —> API Gateway —> HTTP Endpoint (Request returned with status of Request A )

PRIVATE INTEGRATION (VPC Link)

Private Integration uses Network Load Balancer to route requests to targets.

  1. Directly hit the endpoint from Network Load Balancer and see if the response is returned within API Gateway Timeout configured in Integration request.
  2. Check If the status of Network Load Balancer is Healthy
  3. Check the target instances and see if the Memory and CPU Utilization is high causing the server to be slow

If you have any questions related to articles on this website please free to ask in our CloudNamaste discord channel – https://cloudnamaste.com/join-cloudnamaste-discord-community/

Join here directly : https://discord.gg/TEbhdutUDQ

Happy troubleshooting !!