How do I troubleshoot issues related to Amazon EC2 origins in CloudFront?

3 minute read
0

I'm using an Amazon Elastic Compute Cloud (Amazon EC2) instance as the custom origin for my Amazon CloudFront distribution. However, CloudFront is returning an error.

Resolution

Based on the type of error that CloudFront returns, take the following actions to troubleshoot.

CloudFront returns a 502 error

To troubleshoot a 502 error, see the following AWS Documentation:

CloudFront returns a 503 error

If you turned off caching for your CloudFront behavior, then CloudFront redirects all requests to the origin EC2 instance instead of the CloudFront cache. If a large number of incoming requests is overwhelming the origin EC2 instance, then CloudFront returns a 503 error. To troubleshoot this error, see Origin server does not have enough capacity to support the request rate.

If CloudFront can't route the request to the best available edge location and doesn't satisfy a request, then it returns a 503: Capacity exceeded error. For more information, see CloudFront caused the error due to resource constraints at the edge location.

CloudFront returns a 504 error

CloudFront returns a 504 error for the following reasons:

  • The origin returned an HTTP 504 status code to CloudFront.
  • The origin didn't respond before the request expired.
  • A firewall or security group is blocking traffic to the origin.
  • The origin isn't accessible on the internet.

Check for the preceding issues first. If access isn't the issue, then check if there are application delays and server timeouts.

For troubleshooting steps, see HTTP 504 status code (Gateway Timeout).

Redirect errors

If you see a redirect error in your browser, then check the Network tab in your browser developer tools. If you see multiple instances of the same request to the CloudFront distribution, then redirections are causing the browser error.

To resolve redirect errors, take the following actions:

  • Check for location headers in the response header. A location header shows that the browser redirects requests to the location value. To troubleshoot this issue, check redirection rules or configurations on the location where the redirections are sent.
  • Check for the Server response header. For example, you set the Server value to the HTTP server that your EC2 server is hosting the contents on. This setting configures a redirection on the EC2 origin. Either change the configuration in CloudFront or the behavior in the origin server.
AWS OFFICIAL
AWS OFFICIALUpdated 2 months ago