The Invalidation allows us to remove object(s) from the Cloudfront cache before it expires. It allows you to remove a specific object from cache as well use supported wildcard character to remove multiple objects. You can also remove all the objects from cache by using “/*” parameters to invalidation requests. In this tutorial, you will learn how to remove cloudfront cache using AWS CLI or management console. Use one of the blelow methods to create CloudFront invalidations and remove object from cache.

Create CloudFront Invalidation using AWS CLI

Assuming you already have installed AWS CLI on your system. If not, use this tutorial to install and configure aws cli on your system. Now use the following example commands to create CloudFront invalidations and clear files from cache.

Remove specific files from cache. You can define multiple files with full path to remove from cache.aws cloudfront create-invalidation \ –distribution-id EXSE2W0DCDBPB \ –paths “/path/to/example-file.css” “/path/to/example-file-2.jpg” Remove all content from a specific directoryaws cloudfront create-invalidation \ –distribution-id EXSE2W0DCDBPB \ –paths “/static/content/” Remove all objects stored in cacheaws cloudfront create-invalidation \ –distribution-id EXSE2W0DCDBPB \ –paths “/” Create CloudFront Invalidation using AWS ConsoleYou can also create invalidation request from AWS Management Console. Follow the below instructions to create Cloudfront invalidation:

Conclusion

This tutorial explained you to how to clear cache in CloudFront by creating the invalidation request via AWS CLI or Management Console. You can also refer the following Python script to clear CloudFront cache and automate it.

How to Remove CloudFront Cache   TecAdmin - 90How to Remove CloudFront Cache   TecAdmin - 96