How do I resolve HTTP 504 (Gateway Timeout) errors from CloudFront?
Last updated: 2020-06-11
My Amazon CloudFront distribution is returning an HTTP 504 (Gateway Timeout) error. How do I resolve this error?
To troubleshoot HTTP 504 errors, check the configurations on your firewall, security groups, and origin server to identify the source of the errors. For detailed troubleshooting instructions, see HTTP 504 Status Code (Gateway Timeout).
If you're using a custom origin and you can connect directly to the origin, but you're getting 504 errors from CloudFront, then consider increasing the distribution's origin response timeout.
By default, CloudFront allows you to keep the origin connection open for 30 seconds. If your applications need more than 30 seconds to process and then return a response, then CloudFront returns an HTTP 504 error.
Note: To optimize performance, the connection time between CloudFront and the origin should be kept as short as possible. Because of this, it's a best practice that you keep the origin response timeout value as low as possible.
Follow these steps to change your distribution's origin response timeout:
- Open the CloudFront console, and then select your distribution.
- Choose the Origins and Origin Groups tab, and then select your origin.
- Choose Edit.
- Update the Origin Response Timeout value.
- Choose Yes, Edit.
Note: If you're using persistent connections between CloudFront and the origin, be sure that the origin keep-alive timeout value is equal to or greater than the origin response timeout.