Invalidating files
Revision | Date | Description |
|---|---|---|
| 24.07.2024 | Init Changelog |
Introduction
If you need to remove a file from CloudFront edge cache before it expires, you can invalidate the file. The next time a viewer requests the file, CloudFront returns to the origin to fetch the latest version of the file.
To invalidate files, you can specify either the path for individual files or a path that ends with the * wildcard, which might apply to one file or to many, as shown in following examples:
/images/image1.jpg/images/image*/images/*
AWS Management Console
To invalidate files using the CloudFront console, do the following.
Sign in to the AWS Management Console.
In Search Box type CloudFront and choose CloudFront.
Select the distribution for which you want to invalidate files.
Choose Distribution Settings (by clicking ID).
Choose the Invalidations tab.
Choose Create Invalidation.
For the files that you want to invalidate, enter one invalidation path per line.
Choose Invalidate.
AWS Command Line Interface
To invalidate files using the AWS CLI, do steps below. You can skip to step 2 if you already know distribution_id.
List all CloudFront Distributions to get
distribution_id(use query to minimize output):aws cloudfront list-distributions --query 'DistributionList.Items[*].{Distribution_Id: Id, Aliases: Aliases.Items[*]}'possible output:
[ { "Distribution_Id": "<distribution_id>", "Aliases": <domain_list> } ]Invalidate file:
aws cloudfront create-invalidation --distribution-id <distribution_id> --paths <paths>possible output:
{ "Location": "<invalidation_location>", "Invalidation": { "Id": "<invalidation_id>", "Status": "InProgress", "CreateTime": "<invalidation_create_path", "InvalidationBatch": { "Paths": { "Quantity": 1, "Items": [ <paths> ] }, "CallerReference": "cli-1680774803-792167" } } }Wait to invalidation be done:
aws cloudfront wait invalidation-completed --distribution-id <distribution_id> --id <invalidation_id>