Amazon S3 – Is a Separate www Bucket Necessary for Static Hosting?

amazon s3dns

Per Amazon's instructions on hosting a static site on S3, I set my testing site up with two buckets: mydomain.tld and www.mydomain.tld. Per the instructions, the www bucket is configured to redirect to the top level bucket. In Route 53, the main domain is set as an A record alias for the mydomain.tld S3 endpoint, and www.mydomain.tld is a CNAME to the www bucket endpoint. That all works as expected — traffic to the www domain is redirected to the non-www, and the URL is rewritten accordingly.

However I was playing around with the configuration (partly because it seemed a bit unnecessary, and partly because I just wanted to see what would happen), and it looks like the second bucket is pretty much unnecessary. I removed the www bucket, and changed the DNS for the www subdomain to be an A record alias to the non-www endpoint, and it all seems to work as expected.

Am I missing something? Is this going to fail horribly down the road, or are Amazon's instructions just outdated and/or overly complicated? All I want is to redirect www.mydomain.tld to mydomain.tld, which the simpler setup seems to do just fine.

Best Answer

There's no reason why having two A records won't work as you describe it, but the instructions are good practice because you should decide which is the canonical address of your site, www.domain.com or domain.com and redirect to the canonical name. Using two A records will make the site visible at both addresses.

Apart from the aesthetic considerations, this is particularly important for Search Engine Optimization (SEO) purposes as some search engines will treat your site as duplicate content if it visible at two domains.

By doing the redirect, visitors will be redirected with a HTTP 301 Moved Permanently if they go to the other URL and search engines will see that this is just an alias for your main site.