Hosting a Hugo site on S3 using Cloudfront

March 13, 2019

So roughly a month ago, I switched from running this blog, using Jekyll, to using Hugo as the sites, static page generator.

This has given me some headache, I will amid, I must stress out that I simply love working with Hugo. But since the old site used Jekyll I hosted that on GitHub using the GitHub pages, which pretty much gives you everything you need hosting a static site. Like HTTPS etc. (I can’t see anyone running any type of website without using HTTPS). But the switch to Hugo left me with no obvious choice of hosting platform, and for ages, I have been wanting to try hosting something real on AWS.

So after I had migrated all the posts, and decided on a theme. I did a

    aws s3 sync ./public <s3-bucket-name>

voila, my site was “live”, or at least served to the public. But it was not served under my DNS, nor was it served on https, both a requirement for me to call it done done.

First thing first, moving the DNS to AWS Route53 (strictly not necessary, I wanted that any since I was tired of my old DNS provider). this was supported easy, I took a backup of the old configuration and imported. After that, I changed the name-servers at my domain registry. That also went smoothly. so that last thing I need was to add a certificate, and set up a redirect from HTTP -> HTTPS. Not that simple.

To get HTTPS I moved on to setting up Cloudfront, in front of my S3 bucket, making the Cloudfront pointing directly to the S3 reference. This all when fine, until I clicked on my requesting link, which gave me an error

The specified key does not exist

I was frustrated, doing changing the request to gave me the correct layout and no error. why would it not just work

after googling the error in about 30 min I found the answer

You should point to the actual endpoint URL of the S3-bucket, not the internal reference that is suggested by AWS them self :/ I’m hoping they will fix this soon.

After trying to find the link above again, for this article i actually also managed to get the extended story to this issue , which explains that this is due to the fact that S3 has 2 endpoint ‘REST’ and ‘website’ which is varying on there feature set where the website endpoint “magically” (that is NEVER a good word in our industry), resolves /index.html. whereas ‘REST’ does not. And when configuring the Cloudfront it only suggests the REST endpoint.

Tagged: #S3 #AWS #Cloudfront #Hugo