In 2018, I created an article on how to create a static website on AWS.
In 2019, I created an article on how to create a static website on AWS using CloudFormation.
Now, in the final days of 2021, the final chapter has been written: how to create a static website on AWS using Terraform.
Hugo is a static site generator. The purpose of a static website generator is to render content into HTML files before the request for the content is made - increasing performance and reducing load time. To achieve this, Hugo uses a source directory of files and templates as input to create a complete website.
To get started with Hugo, refer to their Getting Started documentation.
Hosting a static website on AWS requires the following resources:
- Amazon S3
- AWS Certificate Manager
- Amazon CloudFront
- Amazon Route 53
First, you must purchase a domain name through Amazon. This can be done through the AWS Management Console.
Creating the Terraform module
This article uses a public Terraform module maintained by Infrable.io:
To use this module the following files are required:
An example Terraform module can be found here.
Deploying the Terraform module
Initialize the Terraform module:
To see the speculative execution plan, run:
If you are satisfied with the output, create the infrastructure:
This can be accomplished with a simple script. See
publish in NickolasHKraus/static-website-com.
The exact steps provided in this article were used to deploy static-website.com!
You might haved noticed that the process for creating a static website on AWS using Terraform is far less cumbersome. This is due to the ease of creating and sharing Terraform modules.