aws-cloudfront-s3-deploy
DEPRECATED: I would instead recommend using AWS' official CLI toolchain for such use cases - Amplify CLI. No updates will be made to this repository
Node.js module that:
- Uploads files at a specified path to a specified Amazon S3 bucket that require updates
- Optionally invalidates the files that were just uploaded in a specified Amazon CloudFront distribution.
This module is not brilliant - I implemented it after incurring costs for invalidating /*
on my CloudFront distribution - with each upload only a few files would be changing, so I wanted a more atomic way to tell CloudFront which files to update. If you do not have this use case - I would recommend using the AWS CLI & a bash script or other such means
Usage
Programmatic
You can use the module programmatically.
let deploy = ; let additionalParams = cli: false verbose: false reuploadAll: false distribution: id: yourDistributionId authentication: profile: yourProfileName keyId: yourKeyId accessKey: yourAccessKey ;
The method has params in sequence:
path
- the path to the directory to upload, this will be excluded on s3 - i.e. if you uploadpublic
, then the contents ofpublic
will be uploaded to the root of your bucket.bucketName
- Amazon S3 bucket name to upload toadditionalParams
- if passed as an option should be an object of type additionalParams.
additionalParams object
Keys as follows:
cli
- boolean indicating whether the program is being run in CLI mode (default:false
)verbose
- boolean indicating whether to run the program in verbose mode i.e. output a message for each upload (default:false
)reuploadAll
- boolean indicating whether to reupload all files regardless of if they have changed (default:false
)distribution
- object containing details of CloudFront distribution, absence will lead to no CloudFront distribution not being updated.id
- ID of Amazon CloudFront distribution
authentication
- object containing authentication options, absence will lead to using system defaults.profile
- identifier of profile in local AWS credentials ini file. (cannot be used in conjunction withaccessKey
orkeyId
)keyId
- AWS access key ID (cannot be used in conjunction withprofile
, must be used in conjunction withaccessKey
)accessKey
- AWS access key (cannot be used in conjunction withprofile
, must be used in conjunction withkeyId
)
CLI
The module can be used from the CLI as follows
aws-cloudfront-deploy --path public --bucket mybucketname --distribution ABCDEFGHIJKLM --profile dev
Options as follows
-V, --version output the version number -p, --path <required> path -b, --bucket <required> bucket name -d, --distribution [id] cloudfront distribution id -p, --profile [profile name] profile to use -i, --keyId [keyId] AWS access key ID -k, --accessKey [accessKey] AWS access key -r, --reupload Re-upload all items -v, --verbose run in verbose mode -h, --help output usage information