Automatically Invalidating S3-Backed CloudFront Objects

To automatically invalidate objects in a CloudFront distribution that's backed by an S3 bucket, you need to do the following:

Setup SNS notifications

You'll need an SNS topic which will be notified when objects are created in your S3 bucket. Then, configure S3 events like so:

Setup the Zap

Then in Zapier, use the SNS New JSON Message trigger, and select your topic:

For your action, use CloudFront Invalidate Item. Choose your distribution, and insert the message subject as a placeholder field - we'll come back to this later:

Then, test the Zap:

You'll now need to add an item to the S3 bucket, so that Zapier is notified via your SNS topic. Once that's done you'll see "OK, found your changes!". Return to the Zap, and replace the subject placeholder field with a leading forward-slash (/) followed by the S3 object key field:

You'll see your field has this value:

And you're all done! Remember that Amazon charges for CloudFront invalidations, and this Zap will invalidate each object individually so it may be expensive.

Was this article helpful?
0 out of 0 found this helpful