Hugo

Hugo Deploy: cloudfront invalidation

Hello,

Perhaps its just me, but I can’t seem to invalidate my Cloudfront with Hugo Deploy. I’m adding the right ID for my cloudfront installation, but nothing happens when I push the changes.

Excellent work with the deployment script btw.

This is one area I haven’t tested myself (I still use my own tool for this), but I’m guessing it’s a “permission thing”, but would expect Hugo to print a warning or something.

No warnings at all, it just doesn’t happen (at least for me). Tried with 2 different buckets, two different cloudfront distributions: nothing.

I have tested both hugo deploy and manually via the aws cli to rule out permission error. The command does upload to s3 but it does not invalidate the distribution if you have duplicated info on the config file.

I was able to get it to work by having the following config.

[deployment]
order = [".jpg$", ".gif$"]

[[deployment.targets]]
name = "s3-aws"
URL = "s3://BUCKET-NAME?region=REGION-GOES-HERE"
cloudFrontDistributionID = "REPLACE-YOUR-ID"

[[deployment.matchers]]
  pattern = "^.+\\.(js|css|svg|ttf|woff|woff2|eot|png|gif|pdf)$"
  cacheControl = "max-age=630720000, no-transform, public"
  gzip = true

[[deployment.matchers]]
pattern = "^.+\\.(html|xml|json)$"
gzip = true
1 Like

What do you mean by duplicated info? Can you give an example?

It turned out to be --invalidateCDN is not getting automatically applied when I do hugo deploy.

The following command works but with CDN invalidation. My understanding is that it is set to default and not required on that command?

hugo deploy --maxDeletes -1 --invalidateCDN

2 Likes

Do you know if there is a way to make this the default?

I didn’t try via Hugo but I wrote myself a deployment bash script.

#!/bin/bash
echo "Deleting old files"
rm -rf public
echo "Generating Files"
/usr/local/bin/hugo --minify
echo "Deploying to S3 and Invalidating CDN"
/usr/local/bin/hugo deploy --maxDeletes -1 --invalidateCDN
echo "Deployment Completed"