Amazon Cloudfront

i have been fighting in my spare time set up Amazon Cloudfront to take some of the hit off my server (i can then run it more efficiently and then save money) i wished i could have used VPS.net‘s akamai offerings but seeing as the idea was to try and save money it would have defeated the purpose. anyway shall post some thoughts now briefly and will later post some more info on how i got things going.

Firstly Cloudfront is a Content Delivery Network (CDN) there core job is to speed up your website by serving all the static files on your website (javascript, css, images and other files – no php) in a normal situation putting these files on another server doesnt neccesarily speed up a site but the core difference between that and a CDN is that the CDN is optimised to serve those files and also a CDN will have what are known as Edge Servers all over the world, the way the CDN works is that it caches all your files on these edge servers and when someone asks for the parts of your website off the CDN they get the server closest to them (closer server is a faster server). There are 2 types of CDN, Origin Pull & Point of Presence and they work in 2 different ways (obviously). by far often the most simple to setup and maintain is Origin Pull, the way this works is you upload your site as normal, you set the CDN to “Pull” its files from your server (like a normal client) and then to get your users to pull from a different CDN’ url for example your site is www.example.com and your cdn is at cdn.example.com your cdn pulls all your images as they are requested on the CDN from www.example.com but you provide links on your site to cdn.example.com. obviously for a big site renaming all those links to images and css files etc will be time consuming so you would need to perhaps use a plugin if you are using a CMS, Rails even has this built in as a configuration line! PoP is slightly different in that you still reference a CDN url but you have to prime the caches by uploading your data to your CDN provider, this obviously takes the pressure of pulling off your server but has the added complexity that you have to make sure files are uploaded, there are tools out there that will automate this part of the task though such as CDN module for Drupal or W3 Total Cache for WordPress.

Amazon Cloudfront is a PoP CDN and uses its S3 service as its origin so you have to manually make sure you have your content loaded up to s3 to make use of it, W3 Total Cache takes care of this and even in the sneak peak i had of the next version supported expires setting and gzip, more on that next time. the actual setup of s3 and cloudfront couldnt have been much easier, i got my Amazon Web Services (AWS) account up and running and enabled s3 and cloudfront. i created my bucket for hosting files and setup the cloudfront distribution attached to the bucket in no time, even setting up the CDN Cname record was quick and easy.

next is uploading content for now i am using W3 Total cache to take care of this but i have had one or 2 issues with url’s not being rewritten properly that i have yet to address, there are however many tools that can be setup to run via cron or in the background to sync your files to S3 s3cmd or s3sync are 2 that come to mind first. Amazon have no origin pull which i think is there first negative.

next hiccup i had was when setting up the site i changed the logo file because i had previously set expires for a week (and for some reason it registered as a year :S) i was stuck with an old file until i decided to just rename the file and force the change. there is a big problem here – i couldnt invalidate the cache on cloudfront as is normal with most other cdn providers, this is a big minus point – the only way to invalidate cache was to delete and recreate the cloudfront distribution which then left me at the mercy of dns propogation for changes.

next thing is gzip, cloudfront wont automatically send files as gzip encoding unless your pre gzip it or set the headers, this means you have to have 2 of all your CSS and JS files one compressed the other uncompressed and then rewrite your css and js rules appropriately depending on browsers this is a large overhead (Luckily solved in upcoming version of W3 Total Cache)

that said Cloudfront is decently fast, its extremely cheap although dont forget to factor in storage costs and it can also host html files with some providers such as akamai wont do on there basic object caching services

its early days and i wish i had a full blown cdn like akamai but cloudfront wins the day for me for the cheap pay as you go costs which work out well for me

Posted in Tech
Tags: , , , , ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.