Local Hugo Deploy S3

Before I jump to an automated GitHub -> S3 deployment for Hugo, I needed to get hugo deploy working for me locally to write changes directly to S3 once I’m happy with a post. I’m a little paranoid about AWS credentials for obvious reasons, so for local work, I like to have specific profiles in my ~/.aws/credentials file. These look like :


Where the given user Hugo has specific access only to the S3 bucket being published to along with the ability to invalidate a cloud front distribution.

I’ve not seen an obvious way to set a specific profile in the Hugo configuration to tell the deploy process to use a specific profile, however it honours the AWS_PROFILE environmental variable. Given that a simple alias will make life easier:

alias hugopub='export AWS_PROFILE="hugo" && hugo deploy'

Adding a Cloudfront distribution in front of the bucket is trivial, but I found one issue on initially rolling it out. Namely, that all my root index.html page worked fine, but that any posts linked in the blog of the form


would fail with a permission error.

Back to AWS school for me, it turns out that even with the Cloudfront ‘Default root object’ set to index.html set a path like the example above isn’t treated as a root object (it’s a specific path). Fortunately, Hugo has a configuration option to create full URLs of the form


instead. Simply add

uglyurls = true

to your config.toml file.