Simple CLI to invalidate cache for AWS CloudFront. You can create invalidation with CNAME.
npm install cloudfront-invalidate-cache --save
Also, you can install with -g
(global) option. Alternatively, you can use npx
to run it without installing.
You need 2 permissions to run cloudfront-invalidate-cache.
cloudfront:CreateInvalidation
cloudfront:ListDistributions
The minimum policy to run is below.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CloudFrontInvalidateCache",
"Effect": "Allow",
"Action": [
"cloudfront:ListDistributions",
"cloudfront:CreateInvalidation"
],
"Resource": "*"
}
]
}
cloudfront-invalidate-cache --cname your.domain.example.com
Or, without installing,
npx cloudfront-invalidate-cache --cname your.domain.example.com
cloudfront-invalidate-cache has only one argument.
CNAME alias for the distribution.
const { invalidateCache } = require('cloudfront-invalidate-cache');
invalidateCache('your.domain.example.com')
.then(() => {
console.log('done!');
})
.catch(err => {
console.error(err);
});