Skip to content

wpkyoto/cloudfront-updator

This branch is 1 commit ahead of master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6d8be94 · Oct 23, 2024
Jun 11, 2020
Jun 29, 2021
Nov 7, 2019
Nov 7, 2019
Jun 29, 2021
Nov 6, 2019
Nov 7, 2019
Nov 6, 2019
Nov 6, 2019
Nov 6, 2019
Nov 6, 2019
Jun 29, 2021
Nov 6, 2019
Jun 29, 2021
Nov 6, 2019
Nov 6, 2019
Nov 6, 2019
Oct 23, 2024
Jun 11, 2020
Nov 6, 2019
Nov 6, 2019
Oct 23, 2024

Repository files navigation

CloudFront Update tools

image

Simple CloudFront distribution config updator.

Badges

NPM
npm version License: MIT Maintainability Test Coverage Build Status

Usage

Configure

import CloudFrontUpdator from 'cloudfront-updator'

const client = new CloudFrontUpdator({
  // You can define your expected the Distribution config
  updator: (id, DistributionConfig) => {
    DistributionConfig.Enabled  = false
    return DistributionConfig
  },
  // You can filter your distributions buy the function
  filter: (distribution) => distribution.Status === 'deployed'
}, {
  // Not running cloudfront.updateDistribution
  debugMode: true | false, // [default] false

  // How to update a several distribution, parallel is fast but sometime the AWS API will be throttle
  taskType: 'parallel' | 'sequential', // [default] sequential

  // If you want to enable / disable your distribution, you should set true
  allowSensitiveAction: false, // [default] false
})

Update All Distributions

After configure the client, just run the method.

await client.updateAllDistribution()

// If you want to update distribution per 10 items.
await client.updateAllDistribution(10)

Upadte Specific Distribution

To run the task, we have to get the specific distribution object.

const {Distribution: dist} = await (new CloudFront()).getDistribution({Id: 'EXXXXXX'}).promise()
if (!dist) return
await client.updateDistribution(dist)

Debug / Dry run

import CloudFrontUpdator from 'cloudfront-updator'

const client = new CloudFrontUpdator({
  // You can define your expected the Distribution config
  updator: ({id, arn}, DistributionConfig) => {
    DistributionConfig.HttpVersion = 'http2'
    return DistributionConfig
  },
  // You can filter your distributions buy the function
  filter: (distribution) => distribution.Status === 'deployed'
}, {
  debugMode: true,
})

const {Distribution: dist} = await (new CloudFront()).getDistribution({Id: 'EXXXXXX'}).promise()
if (!dist) return
await client.updateDistribution(dist)
const diff = client.getDiff()

{
  "added": {},
  "deleted": {},
  "updated": {
    "HttpVersion": "http2"
  }
}

Contribution

// clone
$ git clone git@github.com:hideokamoto/cloudfront-updator.git
$ cd cloudfront-updator

// setup
$ yarn

// Unit test
$ yarn test
or
$ yarn run test:watch

// Lint
$ yarn run lint
or
$ yarn run lint --fix

// Build
$ yarn run build

// Rebuild docs
$ yarn run doc

Commit message rule

The repository runs commitlint. We have to follow "Conventional Commit" to make a commit message.

https://www.conventionalcommits.org/en/v1.0.0-beta.4/

$ git commit -m "<type>[optional scope]: <description>

[optional body]

[optional footer]"