Josep del Río Codes Stuff

My development blog.

Using CloudFront With Octopress

So, once you’ve setup your Octopress blog, where do you host it? I decided to go for CloudFront/S3; again, there were some flaws, so here’s my experience!

I found this nice article about setting up Octopress to use CloudFront; it was quite straightforward, but I needed to call the “s3cmd” script with Python, and use “public/” instead of “public/*”:

Rakefile - rakefile.rb
1
2
3
4
5
desc "Deploy website via s3cmd with CloudFront cache invalidation"
task :s3 do
  puts "## Deploying website via s3cmd"
  ok_failed system("python c:\\s3cmd\\s3cmd sync --acl-public --reduced-redundancy --cf-invalidate public/* s3://#{s3_bucket}/")
end

While this appeared to work properly, in reality I had some problems with the CloudFront invalidation, as some files weren’t invalidated properly; I found out that s3cmd is trying to invalidate the “index.html” files, but since it’s using the S3 static website with CloudFront Custom Origin, in reality it should invalidate the path, not the file; for instance, if we uploaded the file “test/index.html”, we need to invalidate “test/”.

So, I forked s3cmd and modified it so it will get the default index file in S3, and modify the CloudFront invalidation query appropiately; I already sent a request to s3cmd’s author to include my modifications, which can be found in my github fork.

In conclusion, it was more difficult than I expected, but now that it’s set up, it should work smoothly; while S3 is nice, CloudFront should be faster for most visitors!

Comments