Is Your CloudFront Distribution Stuck "In Progress"?

Tired of waiting for your CloudFront changes to propagate? Check out this little hack to speed up your configuration changes

If you’ve deployed a CloudFront distribution before, then you will know first hand how slow this can be.

It gets even more frustrating when you’re tweaking CloudFront behaviour because it’s just not quite working as you would like; best go grab yourself another coffee…

Fortunately, there’s a neat trick you can do to speed up your configuration changes to help you in exactly these scenarios!

CloudFront Invalidations are used to clear cached files at CloudFront Edge locations. What’s quite handy is that wildcard validations to the root also seems to flush CloudFront configuration. The console will still tell you that the status of the distribution is “in progress” and the invalidation itself will take some time, but go ahead and give that URL a refresh. For me, the changes happen pretty much instantly.

How do I invalidate the cache for my CloudFront distribution?

There are a few ways to do this, but I’d suggest either doing it through the console or via the aws-cli for simplicity.

Through the Console

  1. Sign in the CloudFront console and click on the Distribution ID link for the one that’s updating.
  2. Click the Invalidations tab
  3. Click the blue Create Invalidation button
  4. Enter * as the Object path and hit Invalidate

Through the aws-cli

Just run the following:

$ aws cloudfront create-invalidation --distribution-id ${distributionId} --paths "/*"

You can find more information about the create-invalidation command here.

It’s worth noting that invalidation requests aren’t free. AWS give you 1,000 paths a month at no additional change, so unless you’re already invalidating your distribution, or making a bucket load of configuration changes, you should be okay. Fortunately, invalidating the entire distribution with /* counts as a single request. Each additional invalidation path costs $0.005.

Also, if you invalidate all the cache, you will see more traffic hitting your origins. This hack is probably more useful to you when you’re testing CloudFront behaviour before you go live.

So it’s as easy as that! Next time you’re changing CloudFront configuration and you don’t want to hang around watching paint dry, invalidate all the objects in your distribution and save a bucket load of time!

I’m a consultant at The Scale Factory, where we empower technology teams to deliver more on the AWS cloud, through consultancy, engineering, support, and training. We might be able to help you too.