Skip to content

Deploy Tool for CloudFront + S3 with npm scripts.

Notifications You must be signed in to change notification settings

maruware/cfs3-publish

Repository files navigation

cfs3-publish

Deploy and Invalidation Tool for CloudFront + S3 with npm scripts.

ttyrec

Install

npm install -D cfs3-publish

or

yarn add -D cfs3-publish

Usage

  • S3 and CloudFront (using ENV)
const { deployAndInvalidate } = require('cfs3-publish')
// or import { deployAndInvalidate } from 'cfs3-publish' /* TypeScript */

deployAndInvalidate(
  {
    pattern: 'dist/**',
    params: {
      Bucket: bucket,
      'Cache-Control': 'max-age=300, no-transform, public'
    }
  },
  {
    distributionId,
    paths: ['/*'],
    wait: true
  }
)
  • S3 and CloudFront (setting Access Key)
const { deployAndInvalidate } = require('cfs3-publish')
// or import { deployAndInvalidate } from 'cfs3-publish' /* TypeScript */

deployAndInvalidate(
  {
    pattern: 'dist/**',
    config: {
      accessKeyId: 'YOUR_KEY',
      secretAccessKey: 'YOUR_SECRET'
    },
    params: {
      Bucket: bucket
    }
  },
  {
    distributionId,
    config: {
      accessKeyId: 'YOUR_KEY',
      secretAccessKey: 'YOUR_SECRET'
    },
    paths: ['/*'],
    wait: true
  }
)
  • Delete old files
const { deployAndInvalidate } = require('cfs3-publish')

deployAndInvalidate(
  {
    pattern: 'dist/**',
    params: {
      Bucket: bucket,
      'Cache-Control': 'max-age=300, no-transform, public'
    },
    deleteRemoved: true,
    deleteProtectionPatterns: [
      'json/**',
      'videos/**'
    ]
  },
  {
    distributionId,
    paths: ['/*'],
    wait: true
  }
)
  • S3 Only
const { deploy } = require('cfs3-publish')

deploy(
  {
    pattern: 'dist/**',
    params: {
      Bucket: bucket
    }
  }
)
  • CloudFront Invalidation only
const { invalidate } = require('cfs3-publish')

invalidate(
  {
    distributionId,
    paths: ['/*'],
    wait: true
  }
)

About

Deploy Tool for CloudFront + S3 with npm scripts.

Resources

Stars

Watchers

Forks

Packages

No packages published