Invalidate CloudFront caches for a bucket.
npm install s3-invalidate-cloudfrontInvalidate CloudFront caches for a bucket.
!Review
!Version
!Downloads
!Size
!Quality
!Coverage
After uploading to an S3 bucket I need to invalidate the CloudFront cache:
``bash`
> 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:
`bash
> s3-invalidate-cloudfront bucket-name
Deleted cloudfront-distribution-id at path /*
`
Benefits:
- Uses the bucket name which is recognisable and not allocated by AWS like the distribution ID
- Simplifies invalidating caches for a bucket that has multiple cloudfront consumers
I also want to programmatically invalidate caches:
`ts
import { lookup, invalidate } from "s3-invalidate-cloudfront";
lookup("bucket-name", "us-east-1").then((caches) => Promise.all(caches.map(invalidate)));
`
`bash`
npm install s3-invalidate-cloudfront
To make the cli accessible install the package globally with the -g flag or invoke it with npx.
`ts`
s3-invalidate-cloudfront bucket-name
`bash
s3-invalidate-cloudfront
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:
`bash`
yarn install
To run tests:
`bash`
yarn test
To generate the documentation locally:
`bash`
yarn docs
To run linters:
`bash`
yarn lint
To run formatters:
`bash`
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:
`bash``
bump2version patch
- Joel Lefkowitz - Initial work
Lots of love to the open source community!


