shou2017.com
JP

Upload Hugo to S3 Using AWS CLI

Fri Sep 29, 2017
Sat Aug 10, 2024

I switched from Transmit4 to AWS CLI, so here’s a memo from that time.

Prerequisites

Before installing AWS CLI, you need to have Python and pip installed.

First, check if Python is already installed:

$ which python

If nothing is displayed, Python is not installed. Install Python:

$ brew install python3

Next, install pip, which is like the Homebrew version for Python:

$ sudo easy_install pip
$ Enter your password when prompted

This completes the preparation.

Installing AWS CLI

Follow the official instructions:

$ pip install awscli --upgrade --user

Normally, this should complete the installation, but I encountered an error. This is one of the reasons I used Transmit before, but now I can’t avoid dealing with errors.

Found existing installation: six 1.4.1
  DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
  Uninstalling six-1.4.1:

It said Uninstalling six-1.4.1:, but I couldn’t uninstall it. After searching online, I found a workaround:

$ sudo -H pip install awscli --upgrade --ignore-installed six

It worked.

Next, complete the detailed configuration:

$ aws configure
AWS Access Key ID : Check on the AWS website
AWS Secret Access Key : If you forgot the secret key, you'll need to create a new one
Default region name : ap-northeast-1 => This is Tokyo
Default output format [None]: text => Since I'm only using it for Hugo, I'll set it to text for now

Testing by Uploading Hugo’s Public Folder

First, check if you can access S3:

$ aws s3 ls
2017-07-22 16:56:44 shou2017.com

I was able to access it and confirm the bucket.

Move to the public folder:

$ cd public

To upload everything in the local public folder, do this:

public$ aws s3 sync . s3://shou2017.com <= Enter your bucket name here

If moving to the public folder every time is inconvenient, you can do it like this:

$ aws s3 sync --delete ./public s3://shou2017.com <= Enter your bucket name here

That’s it. It was faster than using Transmit, but working with the terminal can still be tedious. Even when following the official instructions, errors often occur.

See Also