Its possible to remove or clear a file from CloudFront Edge caches before it expires time. Have to use Invalidation concept to clear the cache, just follow the steps below,
Step 1: Create a necessary IAM Policies and Roles to access the CloudFront from the CLI.
Step 2: Install AWS-CLI on your local machine, either you're using Windows/Linux/MacOS.
Step 3: Configure the Access Key and Secret Key of the IAM user.
Step 4: Get the CloudFront distribution ID using the command,
$ aws cloudfront list-distributions
You can use Invalidations to clear the cache, add the paths to the files clear the cache from CloudFront Edges. Execute the AWS-CLI command below,
$ aws cloudfront create-invalidation --distribution-id "T8GHKGEXAMPLE" --paths '/location/*'
The output looks like below,
{
"Invalidation": {
"Id": "T8GHKGEXAMPLE",
"Status": "InProgress",
"CreateTime": "2021-10-07T09:31:20.443000+00:00",
"InvalidationBatch": {
"Paths": {
"Quantity": 1,
"Items": [
"/location/*"
]
},
"CallerReference": "cli-1255455-111111"
}
}
}
"Invalidation": {
"Id": "T8GHKGEXAMPLE",
"Status": "InProgress",
"CreateTime": "2021-10-07T09:31:20.443000+00:00",
"InvalidationBatch": {
"Paths": {
"Quantity": 1,
"Items": [
"/location/*"
]
},
"CallerReference": "cli-1255455-111111"
}
}
}
That's it.
Comments (0)