Set the Origin domain using S3 bucket ARN with website
The key for CouldFront setup is to set the “Alternate domain name (CNAME) - optional” This is not optional if you want to use your own domain name. Also important point to set the alternate domain is to get domain certification done. For DNS service Onamae.com which I am using, email certification is another trick part. You need to enable the email certification in Onamae.com (cheap, but not for free…)
One rabbit hole is that you need two distributions for www.domain.com and domain.com.
Another rabbit hole of is that S3 website will not have default object of ‘index.html’ for the non-root directory. The solution is to create a function and attach the function to the ‘distribution’
function handler(event) {
var request = event.request;
var uri = request.uri;
// Check whether the URI is missing a file name.if (uri.endsWith('/')) {
request.uri += 'index.html';
}
// Check whether the URI is missing a file extension.elseif (!uri.includes('.')) {
request.uri += '/index.html';
}
return request;
}