AWS Amplify is an AWS service for building and hosting modern web applications.

This website is generated with Hugo and is built and hosted through AWS Amplify.

The Hugo build configuration is automatically detected and used when creating an AWS Amplify app and pointed to a Git repository.

Outdated version of Hugo

When setting up the AWS Amplify app, however, I noticed that the building of the website failed.

Initially with the following error:

2023-03-23T22:20:07.865Z [WARNING]: Error: add site dependencies: load resources: loading templates: "...": parse failed: template: partials/head.html:46: unexpected unclosed action in command
2023-03-23T22:20:07.868Z [ERROR]: !!! Build failed
2023-03-23T22:20:07.868Z [ERROR]: !!! Non-Zero Exit Code detected

Using a more recent version of Hugo

The default Hugo package is pretty outdated. A newer version can be selected by providing a version number under:

App Settings ➡️ Build Settings ➡️ Build image settings ➡️ Live package updates ➡️ Version

Released versions are on the Hugo GitHub Releases page.

In addition, the version can be set to be latest for using the latest version of Hugo.

Using Hugo extended

Another build error followed after that:

2023-03-25T00:48:00.382Z [WARNING]: Error: Error building site: TOCSS: failed to transform "scss/main.scss" (text/x-scss). Check your Hugo installation; you need the extended version to build SCSS/SASS with transpiler set to 'libsass'.: this feature is not available in your current Hugo version, see https://goo.gl/YMrWcn for more information

It may be required to use the extended version of Hugo, not used by default.

The version string provided in the previous section can be used to download an extended version release of Hugo.

Update the amplify.yml to include pre-build commands for downloading this release as follows:

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - wget https://github.com/gohugoio/hugo/releases/download/v${VERSION_HUGO}/hugo_extended_${VERSION_HUGO}_Linux-64bit.tar.gz
        - tar --overwrite -xf hugo_extended_${VERSION_HUGO}_Linux-64bit.tar.gz hugo
        - mv hugo /usr/bin/hugo
        - rm -rf hugo_extended_${VERSION_HUGO}_Linux-64bit.tar.gz
    build:
      commands:
        - hugo
  artifacts:
    baseDirectory: public
    files:
      - "**/*"
  cache:
    paths: []