I updated files on my origin servers. However, Amazon CloudFront still serves old content to my users.
Short description
By default, CloudFront caches responses in edge locations based on cache-control headers in the response from the origin and the minimum, maximum, and default TTL values in a CloudFront distribution's cache behavior.
Based on the values that you configure, CloudFront serves cached files until the cache expires. To immediately serve updated files, invalidate the files to remove objects from CloudFront's cache.
Note: You can't invalidate specific versions of an object that uses cookies, query-strings, or headers to vary the response. Invalidation removes all versions of the object.
Resolution
Important: Invalidating files might incur charges. For more information, see Pay for file invalidation.
Invalidate files using the AWS Console
To invalidate files using the AWS Console, see Invalidate files to remove content.
Invalidate files using the AWS CLI
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshoot AWS CLI errors. Also, 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"
Note: Replace EDFDVBD6EXAMPLE with the ID of the distribution serving your files.
To find the current status of an invalidation, use the get-invalidation command:
aws cloudfront get-invalidation --id I2J0I21PCUYOIK --distribution-id EDFDVBD6EXAMPLE
Note: Replace EDFDVBD6EXAMPLE with the ID of the distribution serving your files.
To poll the status of an invalidation until it completes, use the following command:
aws cloudfront wait invalidation-completed --id I2J0I21PCUYOIK --distribution-id EDFDVBD6EXAMPLE
Note: Replace EDFDVBD6EXAMPLE with the ID of the distribution serving your files.
Related information
Why is CloudFront serving outdated content from Amazon S3?