I use a Lambda function to resize images when requested on-the-fly by this tutorial.
The general flow is this:
- the bucket (lets call it
mybucket
, name changed) where the resources are stored is configured to work as a website. - a redirection rule is configured when the requested resource is not found. This rule redirects to the API gateway that triggers the Lambda function
Everything works fine when accessing the bucket with its endpoint URL directly. This endpoint URL is:
http://mybucket.s3-website.eu-central-1.amazonaws.com
However, when we now access the resources via the CloudFront distribution URL the redirect doesn't work. The CloudFront distribution is correctly set up. E.g. if we request an existing resource via the distribution URL the resource is delivered. But if we request a not existing resource the redirect is not triggered. If I check the origin settings of the CloudFront distribution I see that the Origin Domain Name is set to
mybucket.s3.amazonaws.com
So, no s3-website and no region!
Q1: Is the missing region the problem why the redirection rules of the bucket are not considered?
I wonder because the Origin Domain Name is selected by a dropdown and there is no region in the suggested buckets. However, I could edit the Origin Domain Name but as this a production system I do not want to mess up the configs.
Q2: what is the suggested setting to use the redirection rules of the Bucket website in combination with a CloudFront distribution?