This site is a static site generated by Hugo and deployed on AWS Amplify. I’d never touched Go before setting this up, but I really liked the speed and simplicity of Hugo, the quality themes available and the fact that it powers some fairly impressive sites I wouldn’t have expected, like 1Password’s support page. I chose AWS Amplify to deploy and host because I have a fair bit of experience with AWS, but none with Amplify so I was curious to see what it could do.

The issue

While I didn’t have any trouble setting up my project and customising it locally, when it came time to deploy, I noticed some inconsistencies in my build artefacts between the local version I’d see by running hugo or hugo server on my machine and what was getting generated and deployed by Amplify.

Tweaks I was making to my theme by overriding certain files in layouts/ were getting ignored, but the build process seemed fine from the logs Amplify outputs, and it took me a while to figure out what was happening because Amplify’s documentation is really scant.

Eventually, I began to suspect it may be a version issue. I confirmed my suspicions by adding - echo $(hugo version) to my amplify.yml file before the - hugo step, and comparing it against my local version.

Amplify output: Hugo Static Site Generator v0.51 linux/amd64 BuildDate: 2018-11-07T10:10:13Z

Local output: Hugo Static Site Generator v0.55.4/extended darwin/amd64 BuildDate: unknown

Now I just had to figure out how to force Amplify to use my more up-to-date version.

The fix

Hugo’s docs for Amplify annoyingly don’t mention anything about specifying the version, so I looked over Amplify’s provisioning logs and found these lines of interest:

ENV VERSION_HUGO=0.51

## Install Hugo
RUN wget https://github.com/gohugoio/hugo/releases/download/v${VERSION_HUGO}/hugo_${VERSION_HUGO}_Linux-64bit.tar.gz && \
    tar -xf hugo_${VERSION_HUGO}_Linux-64bit.tar.gz hugo -C / && \
    mv /hugo /usr/bin/hugo && \
    rm -rf hugo_${VERSION_HUGO}_Linux-64bit.tar.gz

My first thought was to use the environment variables preferences to overwrite VERSION_HUGO, but that doesn’t work because user-specified environment variables aren’t available until the build steps.

Fortunately, there is a workaround. Altering the build script to the below got Amplify to use my version and fixed my issue:

version: 0.1
frontend:
  phases:
    build:
      commands:
        - wget https://github.com/gohugoio/hugo/releases/download/v0.55.4/hugo_0.55.4_Linux-64bit.tar.gz
        - tar -xf hugo_0.55.4_Linux-64bit.tar.gz hugo
        - mv hugo /usr/bin/hugo
        - rm -rf hugo_0.55.4_Linux-64bit.tar.gz
        - hugo
  artifacts:
    baseDirectory: public
    files:
      - '**/*'
  cache:
    paths: []