Amazon S3 + CNAMEs

Amazon S3 is an amazingly simple service to setup and use.  Pricing is very fair, and performance is more than acceptable.  One of the most popular uses of S3 is to serve static website content.  Basically, you’re setting up a poor man’s content delivery network.

Another attractive feature is the virtual hosting of buckets (buckets are like directories within your S3 space).  This allows you to setup CNAMEs for your domain that correspond to S3.  For example, say I just setup example.com.  I want to use S3 to distribute my static content (images, Flash movies, JavaScript files, CSS files).  I upload these files to S3, and then refer to them using something like static.example.comstatic.example.com becomes an alias for S3.

The link above provides a more detailed description of the process, but all you have to do is:

  1. Create a bucket within S3 that is identical to the hostname (for the previous example, the bucket would be labeled static.example.com).
  2. Create a CNAME record static.example.com that points to static.example.com.s3.amazonaws.com
  3. Visit static.example.com/[filename] in your browser to view your files.

About this entry