Archive for December 2010


Setting up Cloudfront with a Custom Origin

December 11th, 2010 — 11:24pm

Our CDN provider, SimpleCDN, looks to be going through some hard times (http://admin.simplecdn.com/), so we’ve had to move our content somewhere else. Immediately, I brought up a new EC2 instance and fired up Varnish to keep things running for now, but that’s hardly a CDN.

Since the content that gets served is very dynamic, we need a CDN that support origin-pull and is, more importantly, competitively priced. We don’t have the traffic to justify a $1k/month CDN bill. Recently, Cloudfront, Amazon’s CDN offering began supporting EC2 origins. Since we run all of our infrastructure on Amazon, this seemed like a great idea. Unfortunately, there is no way to set this up from the AWS Console, so I hacked up a quick script in boto, and thought it was worth sharing.

This uses the latest version of boto (available here). I pull the latest trunk, but you may be able to use one of the distribution versions. The script I used was:

from boto.cloudfront import CloudFrontConnection
from boto.cloudfront.origin import CustomOrigin

c = CloudFrontConnection()

origin = CustomOrigin("www.bigforge.com", origin_protocol_policy='http-only')

distro = c.create_distribution(origin=origin, enabled=True, cnames=['cdn.bigforge.com'], comment='BigForge CDN')

print distro.domain_nam

It should be obvious what you have to change, and what gets printed out should be put in as a CNAME in your DNS. Go to your AWS Console, and you’ll see the Cloudfront distro being deployed. It took a few minutes to change to the “deployed” state.

It’s too bad to see SimpleCDN go, but if you need a mirror bucket solution, this works.

1 comment » | Uncategorized