Use Amazon CloudFront for Fast Web Hosting at a Low Cost


When maintaining a website, content is always going to be your number one priority.  However, you also need to carefully consider two additional factors in order to ensure your overall success.  First off is cost – simply because no one wants to spend too much on web hosting.  Next off is speed.  In a previous article, Jeff outlined some of the reasons why page load times are so important to a site’s overall success and health.

For a couple of months now, I have been using Amazon S3 (Simple Storage Service) to host a handful of files such as screenshots.  More recently I wanted to put together a personal website – nothing fancy; just a couple of HTML documents that would allow me to have a personal online presence.  While I pondered purchasing hosting service, I ultimately decided to use “the cloud” and host my simple site on Amazon S3.  However, I quickly remembered that S3 didn’t allow for “index” files to show up.  So while someone could access my site just fine by going to “www.mysite.com/index.html”, simply going to “www.mysite.com” threw off an error message.

This is where Amazon S3’s sister product – CloudFront – comes into play.  While I have mentioned CloudFront in previous posts, I have neglected to give it the attention that it is truly worthy of.  Not only does CloudFront allow for you to have a “default root object” such as index.html, but it also has the advantage of being a CDN.  That is, the site is stored on seventeen servers throughout the world, ensuring that anyone who accesses your site is directed to the server closest to them.  What does that mean?  Simply put, the load times are going to be blazing fast.

But how do you set up a website on CloudFront?  While Amazon is a great web provider, the one field that they are lacking in is user friendliness.  Unless you want to work with a (rather complex) API, you will need a S3 client to do the dirty work for you.  I previously reviewed a solution called “CloudBerry Explorer” – a product that allows you to navigate the Amazon S3 ecosystem with relative ease.  CloudBerry works with both S3 and CloudFront, making it the one-stop-shop for creating a CloudFront-based site.

Upon launching CloudBerry, you are going to want to supply your Amazon S3 API “key” and “secret”.  These can be found in the account area on the Amazon Web Services portal.  From there, you are going to want to upload all of your files onto a new or existing S3 bucket.  Amazon stores all of the files for your site in a designated bucket, and then has CloudFront replicate the content onto the cluster of servers.  When copying your files over, you will want to ensure that they are all set to be viewable by the public.  From there, you will want to create a new CloudFront distribution – being sure to specify the CNAME that you will later set up with your domain registrar, as well as the “default root object” (usually index.html).

Being a Linux user myself, however, CloudBerry has not been an option for me.  Because of this, I put together a simple script based on the s3cmd command-line S3/CloudFront utility.  The script (located on the forums) allows you to specify a folder containing your site, as well as an API keyset, a bucket name, and an optional CloudFront distribution, CNAME, and default root object.  The great thing about this script is the fact that it does everything from the script – meaning you can set up and upload a CloudFront site entirely from the script.  The only thing you will have to do is update a DNS record with your provider, but that’s simple enough.

All in all, CloudFront is a very efficient content delivery system and can be used as a full-on host for small websites.  However, it still lacks the ability to execute PHP or use MySQL services, so you will not be able to make use of it to host dynamic sites, etc.  If I were to have this sort of need, I would personally use WebAir to host a site or VPS.  However, if you can make use of it, S3 and CloudFront can be a very productive combination – with promotional prices starting at nothing.

Do you use Amazon Web Services?  What do you think about the idea?  Let us know in the comments!