How to Invalidate a CloudFront Download Distribution Object

How to Invalidate a CloudFront Download Distribution Object

AWS CloudFront is a content distribution service offered by AWS to serve low latency content with high data speed. CloudFront caches the object to its edge location. If the user has updated an object before it has expired or before the Cache-control max age, CloudFront will still show the older object. If the user wants to load the updated object, it is necessary to remove the origin object from the CloudFront edge location. This can be achieved with:

  • Invalidating the object
  • Object versioning

The present guide demonstrates how to invalidate an object from a download distribution.

The user can invalidate only objects from the download distribution. The objects from the streaming distribution cannot be invalidated. AWS allows only a specified number of objects to be invalidated as free per month. If the user invalidates more objects, it will be charged as a cost.

The user can have only three invalidations per distribution in progress at one time.

1. Create a bucket with AWS S3. Make the bucket publicly accessible with the access policy. Upload the media file to be distributed using CloudFront to the bucket and make it public.

2. Create a download distribution.

3. Check the object in the browser.

4. Click on the Invalidation tab of the Distribution configurations. Click on “Create Invalidation”.

5. Provide the path of the object that the user wants to invalidate. Only the objects associated with the download distribution can be invalidated. Given below are a few points to be noted before invalidating objects:

a. The user should explicitly invalidate each object as well as the folder.
b. The wildcards are not allowed while specifying the object path (e.g. /mydir/* will not invalidate all objects of mydir folder).
c. The user can specify a leading ‘/’ or skip it. E.g. path “/aws.jpg” and “aws.jpg” are both are valid for the object aws.jpg.
d. If CloudFront is configured to forward the query string, it is required to include the complete query string in the invalidation object. If there is more than 1 parameter in the query for the same object, the user must invalidate the same object for each parameter of the query. (e.g. /aws.jpg?time=2&date=12398749&userid=3&age=20 is required to be invalidated for 4 times with each invalidation specifying as /aws.jpg? time=2, /aws.jpg? date=12398749, /aws.jpg? userid=3, /aws.jpg? age=20)
e. The user can specify a maximum of 1000 objects in one invalidation request.

Click on “Invalidate” after providing the Object Paths.

6. The invalidation process will now be in progress.

7. It may take several minutes (around 10-15) to complete the invalidation process.

8. The invalidation process cannot be run again after it has been completed. The user has to copy the existing invalidation and run it again.

Keywords: Amazon Web Services, AWS, Amazon AWS Console, AWS S3, Amazon CloudFront, AWS CloudFront, CloudFront, AWS EC2, AWS S3, Amazon S3, Download Distribution, CDN

You must be to post a comment.

* As a bonus, you'll receive our weekly newsletter!

Hitchhiker's Guide to The Cloud

Newvem's eBook for Cloud Operations