Clear All Cache of Cloudfront

You must have AWS-CLI tools installed and configured on your system. Open a terminal on your system have aws-cli installed. Execute the following command to create cache invalidation request. Make sure to change YOUR_CF_DIST_ID with the distribution ID of your cloudfront distribution. On success, you will see the results like below. The current status of invalidation is “InProgress”. Note down the Id of the invalidation request to check status of the invalidation requests.

Clear Specific Files from Cache

Instead of clearing all chache, you can clear specific files from Cloudfront cache. For example, you have just updated 1 or 2 files in your application. Now, you need to clear that files only from cloudfront. To clear specific files from cache, execute command as following: The above command will clear only /static/images/newfile.jpg and /static/css/style.css from cloudfront cache, So new files will reflect immediately.

View Request Status of Invalidation

Now, use below command to check invalidation request status. Execute the following command with your cloudfront distribution id and pass the request id to “–id” parameter. See the below example: The invalidation process take less than a minute. Once the invalidation request successfully completed, you will see the status as “Completed”.