Friday, February 18, 2011

Hosting Static Websites on S3: The 99.4% solution

Today, Amazon announced a new feature which allows you to (almost) host a static website entirely on AWS S3. They do this by allowing you to set a default root object for each S3 bucket. Think of the default root object as the equivalent of an index.html default file. This setting tells a web server which file to return to the user when one isn't specifically asked for. For example, when you enter in your web browser, CNN's web server automatically returns

In order for this feature to work, you'd have to configure your domain's DNS CNAME (alias) to point to your bucket. But there's a big gotcha and that's the fact that a CNAME record can only be used with subdomains (i.e.,, and not the root domain (i.e. The DNS RFC directs that the root domain must be an A record which can only point to a numeric IP address.

Amazon Permanent Fix
To fix this problem, Amazon would need to set up servers at a single IP address. Load balancing a single IP address is exactly what keeps the entire DNS root servers alive and running. While there may only be 13 different static IP addresses for the world's DNS root servers, each one is supported by many redundant servers located on different continents. In other words, one static IP address can easily map to an unlimited number of physical servers.

Since an Amazon fix to this problem may not be in the near future - or it might never come - there is a workaround, but it's not as elegant as it could be.

I've actually been using the following technique for a few years at Adjix. When visiting, note that the URL for most of the static web pages at the bottom of the Adjix home page begin with As long as things are working, most people never even notice if a URL begins with www, web, blog, or has no subdomain.

1. Create an S3 bucket called Put an index.html file in there along with all of your website's static content and set the index file as the bucket's root object.

2. Configure your DNS CNAME to point to this bucket (i.e. www should point to

3. This final step is unpleasant and inelegant from a technical point. It involves using a third party service where you can configure our domain's root domain to point to a static IP address. I would be more than happy to host this redirect service for your domain's root A record. If you're interested in using this service then please let me know via e-mail.

Nearly anyone who visits your website, by typing the URL directly into their browser, will either enter or Either method will work since they will be redirected to

While redirects aren't always elegant, you've probably noticed many redirects when logging into your Google account or when accessing a custom domain blog on Posterous. It isn't as clean and quick as it could be, but it doesn't violate any RFCs and it works.

No comments: