Deploying Static Website with Github and AWS Amplify (Tutorial)
Overview
Use Hugo template to publish your static website in minutes.
Steps
- Install Hugo
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
port install hugo
- Download Hugo Template
First, start a new hugo project (replace site name with the name of the folder you want to create on your computer) hugo new site SITENAME
Now you have an empty project. You can add any of the hugo themes (templates) from https://themes.gohugo.io by running the following command:
git submodule add LINK_TO_GIT_REPO.git themes/THEME_NAME
Afterwards, copy and paste all the contents in the folder themes/THEME_NAME to the root directory of the hugo project
- Editing Hugo Template
In order to edit the contents of the website, you go to the following folders:
- content: edit text and images on the website
- static/images: replace media files
- layout: edit HTML structure of the pages
- config.toml: edit page names, order and other website settings
- Github
Before we move to AWS Amplify, create a new git repository and push all the code you have written at this point to a public or private repository.
- AWS Amplify
Next, go to Amazon Web Services (AWS) and create an account if you don’t have one.
Go to AWS Amplify and choose “Host your web app”. Next connect the git repository that contains your code and the branch that you will be hosting the final code on.
In the next page, under the build and test settings click edit. Add the following code under commands:
- git submodule update --init --recursive --depth 1
- wget https://github.com/gohugoio/hugo/releases/download/v0.70.0/hugo_extended_0.70.0_Linux-64bit.tar.gz
- tar -xf hugo_extended_0.70.0_Linux-64bit.tar.gz hugo
- mv hugo /usr/bin/hugo
- rm -rf hugo_extended_0.70.0_Linux-64bit.tar.gz
- hugo
Hit save and deploy and wait for a few minutes to make sure the build was executed without errors.
Using AWS amplify will not cost money as long as you spend less than 1000 build min (average build takes less than 5 min, so you can make approximately 200 pushes to the git repository without paying).