How to Drupal 7, CDN Module, and Amazon Cloudfront in 10 minutes
patrick — Mon, 09/26/2011 - 10:43
Recently I decided to check out Amazon Cloudfront to use as a cdn. I had a delighted experience with it. It was so easy to setup with drupal and configured so easy in just a few steps.
Cloudfront is a pull only cdn as opposed to a push cdn. A pull cdn is a cdn that grabs the files from your site on demand. The only thing you have to do to configure a pull cdn, is switch out the base url of the files you want to serve, to the cdn base url. When that file gets requested the cdn checks if it has it already, if not it downloads it from your server and servers it to the client.
In addition to the easy setup of Amazon Cloud front is it's cost. It is really really cheap. It costs about 12 cents per gigabite of transfer.
Step 1: Create a Cloudfront distrabution
I am not going to walk through the sign up process for amazon web services. It is pretty straight forward you can find it here. Once you have an account you need to sign in to the AWS Management Console. The link is found on aws.amazon.com website at top right hand side.
Next you will get the Management Console for all AWS services. Click on the Cloudfront tab.
Next click the 'Create Distribution' button in the upper left hand side.
You will be prompted with a small configuration screen. Click on 'Custom Origin' and enter your website domain name in 'Origin DNS Name' field and click 'Continue'. NOTE: This is the most basic setup. This can definetly be more complex, but for most users this configuration will work.
On the next configuation screen you can leave everything blank. You can optionally configure a cname. This will allow you to control the url of your cdn. For example, if you wanted everything to come from cdn.example.com you would enter that in, but be aware that you need to configure your DNS appropiatly. Again for most setups you can leave this blank. Click 'Continue'.
Finally you will be brought to the review page, hit 'Create Distribution'.
Next make note of the 'Domain Name' that was assign to you. It should be something.cloudfront.net. It may take a few minutes for the distribution to create it self, but while that is going on, you can install the cdn modle.
Step 2: Install and configure the Drupal CDN module
Now go to drupal.org and download and enable the CDN module.
Once enabled, there is only two simple configuations that you need to do. Go to /admin/config/development/cdn and click on the details tab. In the 'CDN-mapping' textarea paste in the url you got from cloudfront and remeber to put http in front of it and click save.
Lastly, click the 'General' tab at the top right hand corner and check the box to enable CDN.
Thats it! Now all files on your site will be pulled automatically to the cdn and be servered to the world from the closed location.