Deploy and Invalidation Tool for CloudFront + S3 with npm scripts.
npm install -D cfs3-publish
or
yarn add -D cfs3-publish
- 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
}
)