Hosting hakyll site on Amazon AWS

Posted on November 6, 2015
Tags:

After having hosted my web­site on Google App En­gine for a few years I got fed up with the hor­rible per­for­mance (mainly the slow start-up time). I de­cided to look at al­ter­na­tives for my per­sonal web­site. Since I rarely up­date the site, and since static we­biste seem like the new big thing, I de­cided to move to a sta­t­i­cally gen­er­ated site.

For a long time I wanted to have a closer look at Ama­zon’s cloud ser­vices, so why not kill two birds with one stone? A static web­site on Amazon AWS!

Using Amazon S3, one can host files cheaply and re­li­ably: per­fect for a static web­site! Amaz­ingly Amazon al­ready has a nice tu­to­rial on how to get started using S3, which is easy enough to fol­low. It ba­si­cally boils down to set­ting up DNS for your do­main, and cre­ating a bucket.

Cur­rently I use Hakyll, a nice Haskell frame­work in­spired by Jakyll, to gen­erate my site.

After gen­er­ating the site, per the tu­to­rial of Hakyll, the site can be up­loaded to S3. Since the we­b-in­ter­face of S3 leaves much to be de­sired, I opted for a more ef­fi­cient CLI tool.

On Mac OS X this tool can be in­stalled using brew:

brew in­stall awscli

On the first run of aws you have to enter some set­tings to iden­tify your AWS ac­count. After which you cn easily de­ploy your site us­ing:

aws s3 sync _site s3://­do­main.­com/ --re­gion us-east-1

Fur­ther­more, I opted to use Cloud­Front for caching. Why you may ask? Be­cause I can. Other al­ter­na­tives such as Cloud­Flare could be used just as well, how­ever, since I was al­ready using AWS, why not try Ama­zon’s so­lu­tion?

Set­ting up Cloud­Front is re­ally easy.

  1. Create a new dis­tri­b­u­tion
  2. Enter the url of the cre­ated S3 bucket (e.g. in my case os­ter­lund.xyz.s3-web­site-us-east­-1.a­ma­zon­aws.com).
  3. Next, next, next.
  4. Create a DNS CNAME record for the gen­er­ated cloud­front URL.
  5. Wait until the ready!
  6. Enjoy your high­-speed site.

Using Cloud­Front re­duced the la­tency to the web­server from 70ms to about 2ms (which is RE­ALLY good).

In con­clu­sion: mi­grating to AWS was re­ally smooth, and highly rec­om­mended.

blog comments powered by Disqus