S3 Website 404 Redirection Rule not triggering over HTTPS

593 Views Asked by At

When I use custom domain to access S3 Website using https://cdn.example.cz/file.png the 404 redirection rule does not trigger, instead it ends with XML error NoSuchKey.

I have following Redirection Rule that is working properly when using S3 Website endpoint http://cdn.example.cz.s3-website.ap-southeast-2.amazonaws.com/file.png

1

Recently I setup CloudFront and a SSL certificate imported in Certificate Manager to serve this S3 Website on a custom domain cdn.example.cz over SSL (HTTPS), everything works fine, except that the 404 redirection rule does not trigger, instead it ends with XML error NoSuchKey.

Please note that:

  • I am not using Route 53, instead CNAME record for cdn.example.cz with the value CLOUDFRONT_SUBDOMAIN.cloudfront.net
1

There are 1 best solutions below

0
AamirR On

I found the answer in docs.

If the bucket is configured as a website, enter the Amazon S3 static website hosting endpoint for your bucket; don't select the bucket name from the list in the Origin Domain Name field.

As soon as I changed the origin to be the S3 website endpoint, the redirection rule triggered the Lambda function, and the response from Lambda also noticed by CloudFront.

I am not sure if that will help, but I also added following custom error response in CloudFront Distribution > Error pages.

enter image description here