s3-invalidate-cloudfront

S3 invalidate CloudFront

Invalidate CloudFront caches for a bucket.

Review Version Downloads Size Quality Coverage

Motivation

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:

  • 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:

import { lookup, invalidate } from "s3-invalidate-cloudfront";

lookup("bucket-name", "us-east-1").then((caches) => Promise.all(caches.map(invalidate)));

Installing

npm install s3-invalidate-cloudfront

To make the cli accessible install the package globally with the -g flag or invoke it with npx.

Usage

s3-invalidate-cloudfront bucket-name

CLI

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]

Tooling

Dependencies

To install dependencies:

yarn install

Tests

To run tests:

yarn test

Documentation

To generate the documentation locally:

yarn docs

Linters

To run linters:

yarn lint

Formatters

To run formatters:

yarn format

Contributing

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

Contributors

Remarks

Lots of love to the open source community!

Be kind to your mind Love each other It's ok to have a bad day