Last Updated on February 23, 2023
Go to your CloudFront distribution and invalidate the cache
One of the problems that had be really scratching my head when I first starting deploying my Jekyll sites to Amazon S3 was that the buggers didn’t seem to update. I would get the updates I wanted working locally and when I deployed the Jeckyll site to my S3 bucket the public site of the site wouldn’t update.
The Symptom I use the s3_website plugin to deploy to S3 and it’s pretty good with error messages. If a deploy doesn’t work then you’ll get an error message. Simples. What was frustrating was that I was getting no error messages from my S2_website deploys, but the front end of my site wasn’t updating.
The problem I found out that because my Jekyll site is served by Amazon CloudFront the problem was probably related to the CloudFront cache. One of the quirks of CloudFront is that when you update assets in a site (pages, pages, whatever) and don’t change the asset name then CloudFront will pretty much ignore that asset and not distribute it for a while. For example, if you make changes to your Jekyll config file and commit it, then you might not see the changes you’ve made for a while.
The fact CloudFront doesn’t automatically, instantly, purge items from cache when they are updated comes under the category of ‘things I wish I had known before troubleshooting CloudFront.
How to purge the whole CloudFront distribution of your Jekyll
Fortunately clearing the entire cache of your CloudFront facilitated Jekyll site is fairly easy. Go to your distribution in CloudFront, click the tab labelled ‘Invalidations’, then click the ‘Create Invalidation’ button. Next shove a * wildcard character in the box labelled ‘Object Path’, then click the invalidate button at the bottom of the dialogue box.
After a few seconds the status of the Invalidation will show as ‘complete’. Now when you check your front end it should be up to date.
Theoretically Amazon will charge you for purging but only if you purge more than 5,000 times a month! So I shouldn’t worry too much…
If you would like more detailed instructions I recommend you take a look at this guide on ColaWeb