Close

August 17, 2012

S3 Bucket CNAME Tips

We do a lot of work with Amazon’s S3 cloud. With the S3 you can quickly setup a huge chunk of reasonable cost storage and even serve it over a browser. They provide a really long url like “http://WebsiteBuckname.yourdomain.com.s3-website-us-east-1.amazonaws.com/”, which is not very aesthetically pleasing.

Using CNAMES in your hosted DNS, you can shorten the name to be something a little bit simpler like CDN.YourDomain.com.

The trick to getting this all setup cleanly the first time, is how you create your “Bucket” in Amazon S3 in the first place. Always create the bucket name as the exact root URL you want it to be. So for instance, if you want to serve content from http://cdn.yourdomain.com, create a new Amazon bucket called “cdn.yourdomain.com”.

After you web enable the buck and get Amazon’s ubber long URL, you need to add that as a CNAME in your DNS.

So you would create a CNAME for cdn.yourdomain.com and point it to Amazon’s ubber long name (ie: http://cdn.yourdomain.com.s3-website-us-east-1.amazonaws.com). Since Amazon does a full domain match to its buckets, everything will mesh up and you can start serving up content as http://cdn.yourdomain.com/stuff/images.jpg