Deploy Hugo site on S3

August 2017 · 2 minute read


Once your Hugo site is ready to be deployed, simply set up npm with a package.json in your root dir.

  • Test the local server is working correctly:

$ npm run-script start

  • Build your public directory:

$ npm run-script build

  • Copy the contents of the newly created public directory into your s3 bucket

  • Navigate to your s3 bucket url and see your Hugo site.


Create a new s3 Bucket

Create Bucket

https://console.aws.amazon.com/console/home

Console > Login > Services > S3 > Create

  • Name: lib.selenasmall.com
Hint: When naming your bucket, use exactly the url you want to use for your website. This will make it easier to manage subdomains later 
  • Region: Asia Pacific

Upload the contents

  • Click on the bucket:
  • Upload the contents of Hugo Site’s public directory

Bucket properties

  • Static Website Hosting
  • Use this bucket to host a website
    • index.html
    • 404.html

Permissions

  • Bucket Policy
{
	"Version": "2012-10-17”,
	"Statement": [{
		"Sid": "PublicReadGetObject",
		"Effect": "Allow",
		"Principal": "*",
		"Action": "s3:GetObject",
		"Resource": "arn:aws:s3:::lib.selenasmall.com/*"
	}]
}

Check the Bucket is Serving Data

Check that your s3 bucket is serving data correctly at the url provided in “properties”

http://webgeek.selenasmall.com.s3-website-ap-southeast-2.amazonaws.com

Configure your DNS

Services > Route 53 > Hosted Zones

** This may take a few moments to propagate


** If this does not work you may need to try something else…

  • Take a look at https://www.site24x7.com/find-ip-address-of-web-site.html
  • Find the IP address of your new subdomain. It should come back saying that it is pointed to an s3 bucket and provide you the IP of that bucket.
  • Back in the Console, change your record to an A-IP4 address and point it to your IP
  • This should now work in the browser