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"

I’m seeing this behavior too.

hugo deploy --maxDeletes -1 --invalidateCDN isn’t working for me to create an invalidation.

I think the issue might be the cache policy I have set, under Cloud Front Distributions | <DistributionID> | Behaviors.

On an old site I build with hugo, where the default behavior works (to the best of my recollection–haven’t run it in a few months), there is no cache policy listed. Under the new site, where hugo isn’t invalidating things like I expect, I see Managed-CachingOptimized.

Maybe hugo doesn’t play well with that setting?

This is working for me now, a couple days later. I manually invalidated once, after my initial deploy, and now hugo deploy seems to be working for me. Not sure what changed.

2 Likes