Hosting hakyll site on Amazon AWS

Posted on November 6, 2015

After having hosted my website on Google App Engine for a few years I got fed up with the horrible performance (mainly the slow start-up time). I decided to look at alternatives for my personal website. Since I rarely update the site, and since static webiste seem like the new big thing, I decided to move to a statically generated site.

For a long time I wanted to have a closer look at Amazon’s cloud services, so why not kill two birds with one stone? A static website on Amazon AWS!

Using Amazon S3, one can host files cheaply and reliably: perfect for a static website! Amazingly Amazon already has a nice tutorial on how to get started using S3, which is easy enough to follow. It basically boils down to setting up DNS for your domain, and creating a bucket.

Currently I use Hakyll, a nice Haskell framework inspired by Jakyll, to generate my site.

After generating the site, per the tutorial of Hakyll, the site can be uploaded to S3. Since the web-interface of S3 leaves much to be desired, I opted for a more efficient CLI tool.

On Mac OS X this tool can be installed using brew:

brew install awscli

On the first run of aws you have to enter some settings to identify your AWS account. After which you cn easily deploy your site using:

aws s3 sync _site s3:// --region us-east-1

Furthermore, I opted to use CloudFront for caching. Why you may ask? Because I can. Other alternatives such as CloudFlare could be used just as well, however, since I was already using AWS, why not try Amazon’s solution?

Setting up CloudFront is really easy.

  1. Create a new distribution
  2. Enter the url of the created S3 bucket (e.g. in my case
  3. Next, next, next.
  4. Create a DNS CNAME record for the generated cloudfront URL.
  5. Wait until the ready!
  6. Enjoy your high-speed site.

Using CloudFront reduced the latency to the webserver from 70ms to about 2ms (which is REALLY good).

In conclusion: migrating to AWS was really smooth, and highly recommended.

blog comments powered by Disqus