Quick Tip for Easily Deploying Octopress Blog on Amazon CloudFront

Following the quick tips on how to host an Octopress blog on Amazon S3, here is below some additional tips for using Amazon CloudFront.

You’ll need again your s3cmd friend we used before, but the requirements are now to use at least the 1.1.0 beta 1 version (for Amazon CloudFront cache invalidation). In order to automatically invalidate Amazon CloudFront caches when a file is updated, you need to change the Rakefile task:

desc "Deploy website via s3cmd with CloudFront cache invalidation"
task :s3 do
  puts "## Deploying website via s3cmd"
  ok_failed system("s3cmd sync --acl-public --reduced-redundancy --cf-invalidate public/* s3://#{s3_bucket}/")
end

Next, you need to create an Amazon CloudFront distribution:

s3cmd cfcreate --cf-add-cname=www.mywebsite.com s3://www.mywebsite.com

You will end up with an output like this one:

Distribution created:
Origin:         s3://www.mywebsite.com/
DistId:         cf://E1TUI5SG9UNARY
DomainName:     d2ded3kts918b2.cloudfront.net
CNAMEs:         www.mywebsite.com
Comment:        http://www.mywebsite.com.s3.amazonaws.com/
Status:         InProgress
Enabled:        True
Etag:           E3EOW5KJVI2JWC

Now you need to configure your DNS settings and set/add a CNAME so that the www subdomain resolves to your CloudFront distribution domain name (d2ded3kts918b2.cloudfront.net in this example as illustrated on the above output from s3cmd):

www 10800 IN CNAME d2ded3kts918b2.cloudfront.net. 

Again, don’t forget that changes to your DNS configuration can take up to 48 hours to propagate!

After you’ve followed these steps, your blog should be available online only if you add index.html in the URL.

In order to solve that, you need to configure Amazon CloudFront so that it knows that the default file to serve for root is the index.html page:

s3cmd cfmodify --cf-default-root-object=index.html s3://www.mywebsite.com

Deployment is done like before, rake will upload via s3cmd) to your Amazon S3 bucket which serves as a source for your Amazon CloudFront distribution which is in charge of serving all your visitors.

comments powered by Disqus