Error Page Custom Configuration
In this section, you replace the default S3 error response with a custom error page served by CloudFront.
Check the default error response
- Open a browser and request a path that doesn’t exist on your CloudFront domain.
- S3 returns a 403 Access Denied XML response because the object doesn’t exist.
- By default, CloudFront caches error responses for 10 seconds.

Upload the error page to S3
- Create a file named
error.html with a text editor (for example Notepad on Windows or TextEdit on macOS), paste the content below, and save it with UTF-8 encoding.
<html lang="en">
<body>
<h1>CloudFront Lab</h1>
<strong>Ops, this is a nice error page!</strong>
</body>
</html>
- Open the Amazon S3 console, select the lab bucket, and choose Upload.

- Choose Add files, select
error.html, then choose Upload.

- Wait until the Upload succeeded message appears, then choose Close.

- Confirm that the bucket now contains both error.html and index.html.

- Open the CloudFront console, select your distribution, open the Error pages tab, and choose Create custom error response.

-
Configure the response for 403 errors:
- HTTP error code:
403: Forbidden
- Error caching minimum TTL:
60
- Customize error response:
Yes
- Response page path:
/error.html
- HTTP Response code:
200: OK
- Choose Create custom error response.
When the origin returns a 403, CloudFront serves /error.html with status 200 and caches the response for at least 60 seconds.

- The message Successfully created 403 error page appears and the distribution status changes to Deploying.

- After the deployment finishes, request a non-existent path again. Wait at least 10 seconds or use a new random path so you don’t get the cached 403 response from the earlier test.
- The browser shows the custom error page.
- In the browser developer tools (Network tab), the status code is 200 OK, Server is AmazonS3, and X-Cache is Error from cloudfront.
- If you still see the default error, check that the deployment has finished and that the settings match step 2.

-
Choose Create custom error response again and add a response for when CloudFront can’t reach the origin:
- HTTP error code:
504: Gateway Timeout
- Error caching minimum TTL:
5
- Customize error response:
Yes
- Response page path:
/error.html
- HTTP Response code:
200: OK
- Choose Create custom error response.
A short TTL of 5 seconds lets CloudFront retry the origin soon after it recovers.

- The Error pages tab now lists both responses: 403 and 504.

Verify the website
- Open your CloudFront domain in the browser. The home page still loads normally, because custom error responses only apply when the origin returns an error.
