How to store a Cloudfront custom error page in S3

amazon s3amazon-cloudfrontamazon-web-services

I have a Cloudfront plugged on an AWS load balancer.

I saw in the AWS documentation that I can customize Cloudfront custom error pages. I tried to store these error pages in S3 as it is recommended in the AWS doc but it doesn't work. The documentation says :

We recommend that you store custom error pages in an Amazon S3 bucket even if you're using a custom origin. If you store custom error pages on an HTTP server and the server starts to return 5xx errors, CloudFront can't get the files that you want to return to viewers because the origin server is unavailable.

My error page is in S3 with the path 'my-app-bucket/errorpage.html'.

I tried to link this file in the Cloudfront config but I have the following error :

Cloudfront custom error page configuration

If I try the value /my-app-bucket/errorpage.html, Cloudfront redirects the request to my ELB origin and I get a 404.

Who could explain me how I can do this configuration ?

Best Answer

These are hints from https://web.archive.org/web/20140319123040/http://blog.celingest.com/en/2013/12/12/cloudfront-configuring-custom-error-pages/

  • You need to add another CloudFront origin pointing to the bucket where your error page is
  • The cache behaviour of the newly-created origin should have a Path Pattern pointing to the folder (in the error page bucket) where the error pages reside
  • You can then use that path in the Response Page Path when you create the Custom Error Response config
Related Topic