AWS CloudFront custom error page
05 March 2025 | Updated on 09 March 2025
I noticed that my hugo website which is hosted on AWS CloudFront did not show the provided /404.html
error page when you try to open an url path which does not exist. Instead some ugly xml response with the content Access denied (http error code 403) was shown.
Possible reasons
Custom javascript function
At the moment I am not sure if the custom javascript add index.html function creates this problem and usually cloudfront would show a 404 error.
CloudFront and s3 bucket policies
Another problem could be wrong access policies between cloudfront and s3. (s3:GetObject
should be enough I thought.)
Instructions to fix the problem
Anyway… You can create a custom error page redirect in CloudFront to solve this issue.
- open cloudfront distribution in AWS management console
- to to tab Error pages
- click on button Create custom error response
- HTTP error code: 403
- error caching TTL: 10
- customize error response: Yes
- reponse page path:
/404.html
- this page must exist in your distribution/bucket.
- http response code: 404
- reponse page path:
Now you should always see the 404 error page.
Related content
CloudFront is a content delivery network by AWS. You can host your static websites there.
Configure user access to aws s3 bucket. Then you can use aws cli to read/write data.
Switching roles in AWS allows you to access and manage resources from different accounts within your organization without having to log in separately to each one.
I developed a serverless application that captures songs played on my favorite radio station, BrianFM. It also creates a Spotify playlist featuring songs from the past 24 hours.