Invalidate CloudFront caches for a bucket.
After uploading to an S3 bucket I need to invalidate the CloudFront cache:
> aws s3 sync src/ s3://bucket-name
> aws cloudfront create-invalidation --distribution-id cloudfront-distribution-id --paths "/*"
The AWS cli only accepts distribution IDs which then have to be hardcoded. It would be much more ergonomic if I could lookup the matching distribution IDs based on the bucket name:
> s3-invalidate-cloudfront bucket-name
Deleted cloudfront-distribution-id at path /*
Benefits:
I also want to programmatically invalidate caches:
import { lookup, invalidate } from "s3-invalidate-cloudfront";
lookup("bucket-name", "us-east-1").then((caches) => Promise.all(caches.map(invalidate)));
npm install s3-invalidate-cloudfront
To make the cli accessible install the package globally with the -g flag or invoke it with npx.
s3-invalidate-cloudfront bucket-name
s3-invalidate-cloudfront <name>
Invalidate CloudFront caches for a bucket.
Positionals:
name The bucket name [string]
Options:
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
-r, --region Set the AWS region [string] [default: "us-east-1"]
-d, --dry-run Don't make any changes [boolean] [default: false]
To install dependencies:
yarn install
To run tests:
yarn test
To generate the documentation locally:
yarn docs
To run linters:
yarn lint
To run formatters:
yarn format
Please read this repository's Code of Conduct which outlines our collaboration standards and the Changelog for details on breaking changes that have been made.
This repository adheres to semantic versioning standards. For more information on semantic versioning visit SemVer.
Bump2version is used to version and tag changes. For example:
bump2version patch
Lots of love to the open source community!