DEV Community

KenjiGoh
KenjiGoh

Posted on

Automate CloudFront Cache Invalidation

If you are using CloudFront distribution to serve your users, it will be good to be able to automate cache invalidation by using this command:

Replace stackName with the name of your Cloudformation stack.

distributionId=$(aws cloudformation describe-stacks --stack-name stackName --query "Stacks[0].Outputs[?OutputKey=='DistributionId'].OutputValue" --output text)

echo distributionId

aws cloudfront create-invalidation --distribution-id $distributionId --paths "/*"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)