Configure error response behavior - Amazon CloudFront (original) (raw)
Configure custom error responses
You have several options to manage how CloudFront responds when there’s an error. To configure custom error responses, you can use the CloudFront console, the CloudFront API, or AWS CloudFormation. Regardless of how you choose to update the configuration, consider the following tips and recommendations:
- Save your custom error pages in a location that is accessible to CloudFront. We recommend that you store them in an Amazon S3 bucket, and that you don’t store them in the same place as the rest of your website or application’s content. If you store the custom error pages on the same origin as your website or application, and the origin starts to return 5xx errors, CloudFront can’t get the custom error pages because the origin server is unavailable. For more information, see Store objects and custom error pages in different locations.
- Make sure that CloudFront has permission to get your custom error pages. If the custom error pages are stored in Amazon S3, the pages must be publicly accessible or you must configure a CloudFront origin access control (OAC). If the custom error pages are stored in a custom origin, the pages must be publicly accessible.
- (Optional) Configure your origin to add a
Cache-Control
orExpires
header along with the custom error pages, if you want. You can also use the Error Caching Minimum TTL setting to control how long CloudFront caches the custom error pages. For more information, seeControl how long CloudFront caches errors.
Configure custom error responses
To configure custom error responses in the CloudFront console, you must have a CloudFront distribution. In the console, the configuration settings for custom error responses are only available for existing distributions. To learn how to create a distribution, see Get started with a basic CloudFront distribution.
Console
To configure custom error responses (console)
- Sign in to the AWS Management Console and open the Distributions page in the CloudFront console at https://console.aws.amazon.com/cloudfront/v4/home#distributions.
- In the list of distributions, choose the distribution to update.
- Choose the Error Pages tab, then chooseCreate Custom Error Response.
- Enter the applicable values. For more information, see Custom error pages and error caching.
- After entering the desired values, chooseCreate.
CloudFront API or AWS CloudFormation
To configure custom error responses with the CloudFront API or AWS CloudFormation, use theCustomErrorResponse
type in a distribution. For more information, see the following:
- AWS::CloudFront::Distribution CustomErrorResponse in the_AWS CloudFormation User Guide_
- CustomErrorResponse in the Amazon CloudFront API Reference
Generate custom error responses
Create a custom error page for specific HTTP status codes
Did this page help you? - Yes
Thanks for letting us know we're doing a good job!
If you've got a moment, please tell us what we did right so we can do more of it.
Did this page help you? - No
Thanks for letting us know this page needs work. We're sorry we let you down.
If you've got a moment, please tell us how we can make the documentation better.