How do I remove a cached file from CloudFront?
Last updated: 2022-05-27
I updated files on my origin servers. However, Amazon CloudFront is still serving old content to my users. Why is this happening and how can I clear the cache?
Based on the values you have configured, CloudFront serves cached files until the cache expires. To immediately serve updated files, invalidate the files to remove objects from CloudFront's cache.
Important: Invalidating files might incur charges. For more information, see Paying for file invalidation.
Invalidating files using the AWS Console
Invalidating files using the AWS CLI
Note: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure that you’re using the most recent AWS CLI version.
To invalidate files using the AWS CLI, use the create-invalidation command:
aws cloudfront create-invalidation ---distribution-id EDFDVBD6EXAMPLE --paths "/example-path/index.html"
To find the current status of an invalidation, use the get-invalidation command:
aws cloudfront get-invalidation --id I2J0I21PCUYOIK --distribution-id EDFDVBD6EXAMPLE
To poll the status of an invalidation until it completes, use the following command:
aws cloudfront wait invalidation-completed --id I2J0I21PCUYOIK --distribution-id EDFDVBD6EXAMPLE