Ninja Docs Help

Invalidating files

Revision

Date

Description

1.0

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.

  1. Sign in to the AWS Management Console.

  2. In Search Box type CloudFront and choose CloudFront.

  3. Select the distribution for which you want to invalidate files.

  4. Choose Distribution Settings (by clicking ID).

  5. Choose the Invalidations tab.

  6. Choose Create Invalidation.

  7. For the files that you want to invalidate, enter one invalidation path per line.

  8. 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.

  1. 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> } ]
  2. 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" } } }
  3. Wait to invalidation be done:

    aws cloudfront wait invalidation-completed --distribution-id <distribution_id> --id <invalidation_id>
Last modified: 17 February 2025