Hugo + AWS

I’ve finally switched over from my old site (useless, albeit gorgeous, one page cv site) to this new blog. Being a bit obsessive about picking the right tool for the job, it took longer than expected before settling for something that I’d love to use on a daily basis.

WordPress was eliminated right away for being 1) boring and 2) bloated. It would have been easy to run on my current configuration which is a simple VPS from Vultr running a LEMP stack on CentOS. Easy isn’t fun though when you want something exciting.

I’m about to pass my AWS Certified Solutions Architect exam so it was a great time to switch over my personal website. Since I won’t be doing anything dynamic and have no need for a database I went ahead and looked at static site generators. Although Jekyll was tempting as the current front runner, Hugo ended up being my choice through a combination of great reviews, speed and a huge personal interest in starting to learn Go.

One of the most interesting things a static site generator currently allows is the use of a serverless architecture for hosting using AWS new Lambda service.

AWS Lambda

Lambda allows you to run code in response to events on different AWS services and contrary to an EC2 instance which runs continuously, Lambda charges you only for the processing time you actually use, in increments of 100ms. In comparison I was paying $5 USD (around 1 million $ CAD these days) for my Vultr server to serve static content, basically wasting 99% of my capacity.

So for the moment the structure of my website consists of three S3 buckets, a Lambda Javascript + NodeJS function and Route53 for a rock solid DNS. I’d add CloudFront but for the moment I doubt I’ll be reaching a lot of readers.

The only thing I have to do to make a blog post is upload a new markdown file to my input S3 bucket. Lambda has access to the buckets and will run Hugo upon any file being added or deleted and transfer the generated content of the public directory to the bucket which serves the static site. The third bucket only serves to redirect queries from the www sub to the root of the site.

One of the main advantages of this setup, apart from ease of use, is the cost. S3 is basically free with the storage I use and Lambda is priced at 0.000000208$/100ms for my memory requirement. Hugo usually generates a site in under 100ms but the entire event takes around 5000ms which is a whopping 0.0000104$ per blog post!

It’s basically not even worth it to crunch the numbers right now. If I make one (good) blog post a week I still won’t cross the 0.10$ threshold. And that’s including increasing S3 storage costs and Route53 queries.

I made a Hugo theme for this website (it’s called Procrastinate) and it’s available on my Github page. Colours are an improvised dark material design palette which I thought would be really easy on the eyes. Fonts used are Droid Serif, Open Sans and Inconsolata for code snippets (using Prism.js).