Using Amazon S3 and CloudFront on WordPress

Using Amazon S3 and CloudFront on WordPress

For the past six months I have used Amazon Simple Storage Solution (S3) to store all the newly uploaded images on my WordPress installations and it works like a snap. But why should you host all your images on S3 when your can simply upload them to your own hosting account? There are several reasons why S3 storage is a superior solution to using your own hosting :

  • Hosting images on a separate domain speeds up site load times as most browsers can only make two simultaneous requests to a domain. Thus if all your file are on a single domain the requests are queued and handled two at a time which slows the load time.
  • Moving hosts is easier if the file locations do not change (a major difficulty in changing hosts is downloading, then uploading all the images and finally changing all <img> the references in your articles).
  • If the files are on S3 it is very easy to transfer them to Amazon’s CloudFront Content Delivery Network (CDN).  CloudFront will give an additional performance boost for user’s who are located geographically far away from your server as CloudFront caches the files in 14 locations around the world.
  • If you are approaching your hosts storage limit then using S3 will probably be cheaper than purchasing additional storage space on your host.

The S3 for WordPress plugin modifies the standard WordPress image upload dialog to upload the images to your designated S3 bucket, from there uploading files to S3 is seemless as it is the standard file uploading process.
You will of course require an S3 account, and you should add a separate ‘bucket’ for file storage (buckets in AWS are similar to directories).

CloudFront in WordPress

Any file stored in S3 can be used with AWS’s CloudFront CDN. To use CloudFront you are required to sign up for it separately to S3 (you can sign up here)  Files served by CloudFront must exist in S3 and when a file is requested from CloudFront, CloudFront initially requests the file from S3 and then caches it at one of its edge locations.

Once you have an account at CloudFront, login to the AWS Management Console and navigate to the CloudFront tab. Under a single CloudFront account you can have various Distributions which are essential ‘buckets’ of storage which can have different attributes.  Click the Create Distribution button which will open the setup dialog, where you choose whether to use Download (for images) or Steaming (for video) and associate the Distribution with an S3 bucket. Once the Distribution is created, you will  be given a unique domains which will look like dxabw2ae51eqo.cloudfront.net , to request your files from CloudFront simply replace your S3 domain (in the format bucket_name.s3.amazonaws.com) with your CloudFront domain on all your file URL’s – the file names will remain unchanged. Unfortunately the S3 plugin in WordPress only works with S3 and you must manually change the file URL’s after uploading although a global find/replace plugin can be used for this.

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!