Skip to content

Latest commit

 

History

History

cloudfront-invalidation

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@reapit-cdk/cloudfront-invalidation

npm version npm downloads coverage: 99.02%25 Integ Tests: ✔

CloudFront invalidations are very error prone, making it hard to invalidate distributions reliably. This construct aims to solve this problem by using a step function which is triggered on stack update, and uses exponential backoff to retry the invalidation. Inspired by aws/aws-cdk#15891 (comment).

Package Installation:

yarn add --dev @reapit-cdk/cloudfront-invalidation
# or
npm install @reapit-cdk/cloudfront-invalidation --save-dev

Usage

import { Stack, App } from 'aws-cdk-lib'
import { Distribution } from 'aws-cdk-lib/aws-cloudfront'
import { HttpOrigin } from 'aws-cdk-lib/aws-cloudfront-origins'

import { CloudfrontInvalidation } from '@reapit-cdk/cloudfront-invalidation'

const app = new App()
const stack = new Stack(app, 'stack-name', {
  env: {
    region: 'us-east-1', // region must be specified
  },
})
const distribution = new Distribution(stack, 'distribution', {
  defaultBehavior: {
    origin: new HttpOrigin('example.org'),
  },
})
new CloudfrontInvalidation(stack, 'invalidation', {
  distribution,
  items: ['/index.html', '/config.js'], // path patterns you want invalidated
})