0
votes

I'm trying to get my naked URL to redirect to www subdomain.

The current website is up and running serving the content from an S3 bucket via cloudfront: https://www.gauntface.com.

Now I'm trying to set up a redirect for http://gauntface.com to https://www.gauntface.com.

I've created a new S3 bucket with no contents but set up with static site hosting and redirects to https://www.gauntface.com. The URL provided by the S3 bucket works correctly and redirects.

I then tried setting up cloud front to serve content from this new bucket but I get an Access Denied error. I'm getting the impression that cloudfront will access the S3 bucket via Rest API meaning it ignore the static site hosting configuration.

So next I'm trying to set up a custom domain to use the S3 bucket directly but so far my CNAME record in namecheap doesn't seem to work and I fear that it won't support SSL.

Can anyone point me in the right direction?

1
There are two ways of using S3 with CF: one is by using S3 in website mode, and second through Origin Access Identity. If you use the former, you have to provide url of the bucket to CF.Marcin
I wrote an indepth article after struggling with this. medium.com/@kylecalicast/… My setup is a private S3 bucket to Cloudfront and even has HTTPS.Kyle Calica-St

1 Answers

0
votes

This was largely thanks to Marcin in the comments.

From what I can gather, setting cloudfront distrbution to have an Origin Domain Name set to the S3 Bucket will cause cloudfront to use the rest API to access files in the bucket, which in this case do not exist.

Changing Origin Domain Name to the endpoint provided by the S3 bucket > Properties > Static Website Hosting will make cloudfront make network requests to the buckets static server meaning it'll receive and forward the redirect response.