How To Remove Cloudfront Cache Using AWS CLI Or Management Console [ Solution ]
Amazon Web Services’ CloudFront is a well-known caching and content delivery network service. It uses its global data centers to provide data to consumers. CloudFront also creates a local cache of content on its servers, which it then utilizes to respond to user requests more quickly.
Table of Contents
Remove Cloudfront Cache
Before the Cloudfront cache expires, we may use the Invalidation to remove the object(s) from it. It allows you to remove a single object from the cache as well as numerous objects using the allowed wildcard character. You may also use the “/*” parameters in invalidation requests to remove all items from the cache.
You will learn how to remove the CloudFront cache using the AWS CLI or management console in this tutorial. To make CloudFront invalidations and remove an object from the cache, use one of the methods listed below.
Using The AWS CLI, Create CloudFront Invalidation
Assuming you already have AWS CLI installed on your machine. If not, follow the steps in this tutorial to install and configure Amazon Web Services CLI on your system.
To create CloudFront invalidations and clear files from the cache, use the example commands below.
- To Remove specific files from the cache. You can remove several files from the cache by specifying their full paths.
aws cloudfront create-invalidation \ --distribution-id EXSE2W0DCDBPB \ --paths "/path/to/example-file.css" "/path/to/example-file-2.jpg"
- Remove all content from a specified directory
aws cloudfront create-invalidation \ --distribution-id EXSE2W0DCDBPB \ --paths "/static/content/*"
- Remove all objects from the cache.
aws cloudfront create-invalidation \ --distribution-id EXSE2W0DCDBPB \ --paths "/*"
Using AWS Console, create a CloudFront Invalidation
- In the AWS Management Console, go to CloudFront.
- To open the CloudFront ID configuration, select it from the list.
- Select the “Invalidations” tab.
- Select “Create Invalidation”
- To remove the cache, enter file names with full paths. You can also use the wildcard “*” as a name.
- Use “/*” to remove all cache. After that, click the Invalidate button.
- Wait till the invalidation procedure is finished.
- All done.
This tutorial shows you how to create an invalidation request in CloudFront using the AWS CLI or Management Console.
You may also use the Python script to clear the CloudFront cache and automate the process.
How to Spend a Weekend in Los Angeles
Los Angeles has it all: sunshine, beaches, spunky speakeasies, and Hollywood stars! Even if you only have a weekend in…