aws/cloudfront-invalidate

Invalidate CloudFront Cache

Purge cached objects from a CloudFront distribution.

aws
cloudfront
invalidate
cache

Command

aws cloudfront create-invalidation --distribution-id DIST_ID --paths "/*"

Explanation

Removes specified objects from CloudFront’s cache so that the next viewer request fetches the latest version from the origin.

Common Use Cases

  • Clearing outdated static assets after deployment
  • Ensuring new frontend builds are served immediately

Best Practices

  • Invalidate only changed files when possible
  • Automate invalidation after CI/CD deployments

Common Mistakes to Avoid

  • Invalidating `/*` unnecessarily (can increase costs)
  • Using wrong distribution ID

Troubleshooting

Problem: Invalidation not reflected

Solution: Wait a few minutes—invalidations are eventually consistent.

Problem: Access denied

Solution: Ensure `cloudfront:CreateInvalidation` IAM permission is granted.

Examples

Invalidate all objects in cache

aws cloudfront create-invalidation --distribution-id E123456 --paths "/*"

Invalidate specific paths

aws cloudfront create-invalidation --distribution-id E123456 --paths "/index.html /app.js"