When creating my new blog, I was torn on whether to use github or cloudfront, s3 and route53 for hosting. Github is great since it’s completely free, but the limitation of only one top level domain was a deal breaker for me. I like having the flexibility of using a custom domain name for my open source projects.
I was also torn whether it’s worth it to pay a little extra for the aws dns service, route53 versus just using godaddy’s dns. After the large outage of godaddy’s dns recently, I’ve decided to use route53 from now on.
There are a few bonuses with using AWS in addition to being able to use more than one domain name, and not worrying about godaddy’s dns system going down again. Github’s terms of service says nothing about putting advertising on sites hosted there, but I’ve never seen it done. It could potentially be not allowed, requiring switching hosts in the future. It’s also nice playing around with AWS in general for learning purposes. Plus, if your blog gets huge, github won’t potentially shut it down.
I’ve done this setup manually before, and had meant to put a blog post up about it, but hadn’t and by the time I went to do this setup a second time I had completely forgotten how to do it. So I decided to create this blog post. In the process of spending most of a day creating this blog post, I remembered what a pain it was to do this, and thought it would be cool if this was just built in to Octopress.
I looked into it, and found out someone had submitted a pull request to Octopress to do exactly this, but it had been declined. Bummer! So I forked the fork which did all this automatically. However, the fork didn’t work out of the box, so I learned enough ruby to get it working, and rewrote this blog post to match the far simpler resulting instructions. It literally cut out about 25 steps. I hope it saves you some time.
Cloudpress Setup Instructions
- Install git
- Install RVM: `curl -L https://get.rvm.io | bash -s stable –ruby’
- Install Ruby 1.9.3:
rvm install 1.9.3
rvm use 1.9.3
rvm rubygems latest
ruby --versiondoesn’t return 1.9.3, visit the rvm site for help.
- Clone the repo:
git clone https://github.com/cloudpress/cloudpress.git <YOUR_BLOG_NAME>
- when cd-ing into your blog directory, if you are asked if you want to trust the .rvmrc file, type yes
gem install bundlerand
bundle installto install dependencies
rake installto install the default theme.
- edit _config.yml to suit your needs, taking care to fill in
aws_secret_access_key. Create an amazon account if you don’t already have one. Log in, and click on your name in the upper right hand corner, then click ‘Security Credentials’ to find your access key id and secret access key. Your url config entry must start with http://www. as in http://www.david-j-nelson.com
- Create a new post:
rake new_post["title"], then open the file this creates in the
source/_postssubdirectory. Edit this post, using markdown for formatting.
- To view your site locally and regenerate your blog every time you make a change, run
rake previewand point a browser to http://localhost:4000
- There is a lot more to the underlying Jekyll and Octopress. For great documentation on Octopress, visit Octopress.org
rake aws:cloudfrontThis will only upload files that have changed, and invalidate those changed files on cloudfront so they are served to your visitors. Cloudfront invalidation can take a few minutes.
- Make note of the four fully qualified domain names the tool outputs, which you will need to use to set your nameservers at your domain registrar in the next section.
- For the initial nameservers, you can issue this in chrome to usually speed up the time it takes to see the changes: Navigate to
chrome://net-internals/#dnsand press the “Clear host cache” button. Also, on osx,
dscacheutil -flushcachecan speed things up.
Registrar Setup Instructions
- Register your domain name if you have not already. I used godaddy to register my domain, but due to their recent bad outage, I’ll use route53 for dns by pointing the nameservers to route53. Log into godaddy, and click on the my ‘My Account’ button, then click on the ‘Launch’ button to the right of ‘Domains’. These instructions will differ slightly with a different registrar, but the same basic concept applies.
- Click on your domain name from the list of domains.
- Under ‘Nameservers’, click ‘Set Nameservers’
- Check the radio button next to ‘I have specific nameservers for my domains’, and click the ‘OK’ button.
- Copy and paste the four fully qualified domains from the output from the tool output mentioned in the previous section, and click the ‘OK’ button.
Amazon Web Service’s Pricing Considerations
Amazon web services are not free, but the cost isn’t a deal breaker for me. Route53 is $0.50 per month for the first hosted zone, and $0.10 a month for the next ones. S3 per month is $0.125 per GB of storage, $.01 per 1,000 PUT requests used when you deploy, .01 per 10,000 GET requests used by cloudfront pullling the files from S3 as its origin, and free for data transfer out up to 1GB. Cloudfront per month is between $0.12 and $0.25 per GB of data transfer depending on which regiion it’s served from, $0.0075 per 10,000 requests, and $0.005 per file for invalidation requests over 1,000 per month.
So, if my octopress site is consumed mostly by U.S. and European visitors, contains 100 files, has an average pageview size of 200kb comprised of 10 objects of an average object size of 10kb, 10 files get transferred for each pageview, I get 10,000 pageviews per month, do 10 deploys a month and only transfer changed content, my cost is about $0.70 per month per site. The cost for the first site is about $1.10 per month.
For a site with 10GB of content, and 10,000,000 pageviews per month, an average pageview size of 200kb comprised of 10 objects of an average object size of 10kb, with 200 deploys done per month, 50% U.S. traffic, and 10% traffic an all other regions, you’re looking at a cost somewhere in the range of $480 a month. Not bad at all! This calculation however did inspire me to want to concatenate, minify and gzip all files used in Octopress to push this cost lower. If done, the cost would drop to roughly $320 per month for this scenario.
- Since a cname cannot be used from the zone apex of your domain, the free and awesome wwwizer service is used automatically to do this for us. Wwwizer will redirect all traffic to your zone apex (ie: david-j-nelson.com) to the www subdomain (ie: www.david-j-nelson.com) using a search engine crawler friendly 301 redirect.