I recently got myself my own domain and wanted to create a blog or a simple page. I’ve been writing stuff in medium but didn’t like the way to write code, so I decided to create a blog with hugo and host it in aws s3.

The first step is to download hugo and install it, so go to https://gohugo.io/getting-started/installing/ and follow the instructions. Once it is installed I downloaded a theme and created a first post. For the infrastructure I decided to go to AWS.

The infrastructure is created with terraform.


provider "aws" {
    region = "us-east-1"
}

variable "www_domain_name" {
    default = "bucketname"
}

resource "aws_s3_bucket" "www" {
    bucket  = var.www_domain_name
    acl     = "public-read"
    policy  = file("policy.json")
    website {
        index_document = "index.html"
        error_document = "404.html"
    }
}

policy.json

{
    "Version":"2012-10-17",
    "Statement":[
      {
        "Sid":"AddPerm",
        "Effect":"Allow",
        "Principal": "*",
        "Action":["s3:GetObject"],
        "Resource":["arn:aws:s3:::bucketname/*"]
      }
    ]   
}

Once this files are created, just apply terraform plan & terraform apply to create the bucket.

To deploy it I can either use aws cli with the command: aws s3 sync public/ s3::bucketname*

or directly in hugo config file I can specify the deploy destination.

baseURL = "https://example/"
languageCode = "es-mx"
title = "Ramon's Blog"
theme = "ananke"

[deployment]
[[deployment.targets]]
name = "site"
URL = "s3://bucketname?region=us-west-2"
cloudFrontDistributionID = <ID>

In this case the deploymnent part of the file indicates a deployment target (multiple deployment targets can be specified), the name of the deployment, the URL of the S3 bucket, and the cloudfront distribution ID.

This is just a first step in the next post I’ll talk on how to create a cloudfront distribution, route53 record and certificate.

devops  IT