Speed Up Amazon S3 with a Content Delivery Network

Amazon S3 and CDNify

Amazon S3 isn’t a CDN!

Not too long ago I was approached by someone asking “Why don’t you have Amazon S3 integration? What’s stopping me just from using them?“, to which I replied “We do, and nothing“.

To clarify, S3 is a storage service, perfect for hosting files away from an origin server or actually as an origin server, but it wasn’t built with web performance in mind. Don’t get me wrong, it’s great for doing those little things like storing all your images and scripts, but when it comes close to high volume traffic it struggles.

Pricing Comparison

To understand the difference between S3 and a CDN, it’s best to start at pricing. Testing just the data transfer out in the US-east region for S3, I compared monthly data usage and cost against CDNify.

Data Amazon S3 CDNify Difference
500GB $303.96 $30.00 $273.96
1TB $366.84 $60.00 $306.84
2GB $489.72 $100.00 $389.72

The monthly pricing from S3’s data usage clearly show just how costly it can be, but that’s not to say you should abandon it, instead it makes more sense to use their free package and integrate a CDN, so you have best of both worlds.

Integrating S3 and CDNify

Personally I’m not one for long guides – The shorter and simpler it is, the better. Integrating S3 with CDNify is easy enough to implement in 3 steps.

  1. Setup Bucket

    Within S3, go to the management console and select Create Bucket. Call the bucket something meaningful for it’s purpose, e.g. “cat-pictures”, choose your region (this can be anything you like), and click Create.

    Select your newly created bucket and click Upload. Choose an image so you have something to work with and then hit Start Upload. Now select Properties, then drop down Static Website Hosting. Click Enable website hosting and within Index Document input a your index file, e.g. “index.html”, then save the changes.

  2. Update Permissions

    Grab and modify the following code, changing “example-bucket/” to your bucket name, e.g. “cat-pictures/“, then copy it.

    {
    "Version":"2012-10-17",
    "Statement":[{
    "Sid":"PublicReadGetObject",
    "Effect":"Allow",
    "Principal": {
    "AWS": "*"
    },
    "Action":["s3:GetObject"],
    "Resource":["arn:aws:s3:::example-bucket/*"
    ]
    }
    ]
    }

    Within S3’s management console, drop down Permissions, then select Add bucket policy – Paste in the code you modify above, then save it.

    Now check that the bucket is working by visiting the image you uploaded previously, e.g. “cat-pictures.s3-website-us-east-1.amazonaws.com/cat.jpg

  3. Create Resource

    Go to CDNify’s dashboard and click Create Resource. Paste your bucket name within Resource Origin, e.g. “cat-pictures.s3-website-us-east-1.amazonaws.com/“, then set a Resource Name, e.g. “cats“, then hit Create.

    Check that everything is setup correctly by accessing your bucket’s image, in this instance it will be “cats.a.cdnify.io/cat.jpg“. Now your assets are being served from CDNify to improve your site’s performance.

Conclusion

S3 is a storage service for hosting files, in reality it’s great at doing that, but it wasn’t built for web performance in mind.

Much like any other site hosted with a web provider, download times can be sluggish when it comes to real amounts of traffic. Instead, it’s better to look elsewhere to handle your site’s performance – This is where a CDN comes in handy.

By implementing S3 with CDNify, you can reduce costs and ensure your assets are guaranteed delivery at super fast speeds across a global network of servers.

Get to grips with S3 by checking out the Integrate CDNify with Amazon S3 guide.

Enjoyed this blog post?