Cloudfront exception “The If-Match version is missing or not valid for the resource.” when updating distribution

Question:

When updating a Cloudfront distribution using the AWS Node SDK I get the following exception:

What am I doing wrong here?

Answer:

This error occurs because you need to first get the current distribution config with cloudfront.getDistributionConfig and then copy the ETag and DistributionConfig fields into your cloudfront.updateDistribution call. You modify the DistributionConfig as needed to achieve the actual config update you’re trying to do.

The docs do a poor job of explaining this (the instructions are for the REST API instead of the actual SDK you’re using).

The following is an example of updating a Cloudfront distribution to be disabled by pulling the latest distribution config, modifying it, and then performing an update with it:

Leave a Reply