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

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
CNAMErecord forcdn.example.czwith the valueCLOUDFRONT_SUBDOMAIN.cloudfront.net
I found the answer in docs.
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.