This is an update on the technical stack of my website. I was able to get Hugo site hosted on S3 based website hosting. I then setup CloudFront based distribution with S3 bucket as Origin. I used CloudFront, not for performance reasons, but to enable HTTPS support. I created custom SSL certification using ACM and set up my custom domain to point to CloudFront distribution using Route53. I set up the whole process as CodeBuild script.

Below are some of the notes for each software stack to get this whole setup working.

Hugo

  1. Ensure that your baseUrl in your config.toml ends with /, if not URLs will not be correct.
  2. If you are using git for your code repository, ensure you have some files in empty directories as git does not store empty directories.

S3

  1. Ensure you have enabled website hosting for your S3 bucket.

CodeBuild

  1. Attached is the buildSpec.yml file for CodeBuild.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
version: 0.2

phases:
  install:
    commands:
      - echo Build started on `date`
      - echo Installing Hugo
      - cd ~
      - wget https://github.com/gohugoio/hugo/releases/download/v0.37.1/hugo_0.37.1_Linux-64bit.deb
      - dpkg -i hugo*.deb
      - hugo version
  build:
    commands:
      - echo BUILD phase commands
      - cd $CODEBUILD_SRC_DIR
      - pwd
      - hugo -v
      - aws s3 ls
      - aws s3 sync --delete public s3://{bucketname}
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:

CloudFront

  1. Ensure that you are pointing to S3 website hosting endpoint.
  2. Make sure Origin setttings are point to the exact location in S3 bucket.
  3. Ensure that you update Hugo site’s baseUrl CloudFront distribution url.