Skip to main content

Streamlined Blogging: How to Use Hugo, GitHub Actions, and S3 for Hosting - Part 1

After a hiatus of 12 years since my last Blog post, I have decided to rekindle my blogging journey. In selecting the blog engine, several criteria were paramount:

  • Markdown compatibility.
  • Capability to be hosted on Amazon S3 as plain static HTML.
  • Version control for posts (ideally through GitHub).
  • Customizability.

After conducting some research, I discovered Hugo, a lightweight static site generator written in Go, which precisely met my requirements.

The initial challenge, as anticipated, was selecting a suitable theme. Fortunately, the official Hugo website offers a plethora of free themes After experimenting with several options, I settled on Anubis, which perfectly aligned with my vision.

Hugo

I won’t delve deeply into the details here. The Hugo website provides comprehensive documentation, which I found to be quite informative and helpful.

AWS

Create an S3 bucket for the blog

  • Create a bucket that matches the subdomain name
  • Make sure to disable (block public access)
  • Update the bucket policy to grant access to s3:GetObject for all objects in this bucket, the policy should be something like this:
{
  "Id": "policyId",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "statementId",
      "Action": [
        "s3:GetObject"
      ],
      "Effect": "Allow",
      "Resource": "bucket-arn/*",
      "Principal": "*"
    }
  ]
}
  • Under properties, enable status website hosting

Configure CloudFront

Create a new cloud front distribution for the new subdomain as follows:

  • From distribution -> Create distribution
  • Choose the s3 bucket as the origin domain, and use website endpoint
  • Under alternate domain name (CNAME), add the target URL (subdomain)
  • If you have ACM certificate configured, enable redirect to https (Under viewer, choose redirect HTTP to HTTPS)
  • If you have ACM certificate configured, choose the correct certificate (Custom SSL certificate)
  • Choose WAF option (can add extra hosting cost)
  • Create distribution
  • Wait until the distribution is fully deployed before moving to the next step (should take a few minutes), otherwise the distribution will not show up as an option

Configure Route53

If you already have a domain name, add a new subdomain as follows:

  • Route53 -> Hosted zone -> Choose the target hosted zone name to add the subdomain to
  • Create record -> Simple routing -> Define simple record
  • Add the new subdomain name
  • Choose record type “A - Routes traffic to an IPv4 address and some AWS resources”
  • From value/route traffic to, choose Alias to cloud front distribution
  • Define simple record, then create records

Conclusion of Part 1

In the upcoming Part 2, I will delve into a more detailed explanation of GitHub and GitHub Actions.