Syncs a local directory to an AWS S3 bucket, optionally invalidating affected CloudFront paths.
npm install --save deploy-aws-s3-cloudfront
This packages uses the AWS SDK for Node.js and defers authentication to the SDK.
If you are relying on credentials stored in ~/.aws/credentials
you can use AWS_PROFILE=<profile> deploy-aws-s3-cloudfront ...
to use a custom-named profile.
deploy-aws-s3-cloudfront --bucket <bucket> [options]
A canned ACL string. See https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property for accepted values.
AWS S3 bucket name to deploy to.
Delete files from AWS S3 that do not exist locally.
Path to remote directory to sync to.
AWS CloudFront distribution ID to invalidate.
No invalidation is performed if this option is omitted.
Pattern(s) to exclude from deployment.
Refer to the fast-glob documentation for supported patterns.
Set the invalidation path (URL-encoded if necessary) instead of automatically detecting objects to invalidate.
This can be used to explicity set the invalidation path rather than have the paths generated from the changeset.
This option is typically used to reduce invalidation costs by using a wildcard pattern (e.g. --invalidation-path "/*"
).
Disable caching of specified S3 path(s). Paths ending with a *
will be treated as wildcards.
Do not prompt for confirmation.
Use recommended settings for create-react-app
s and disable caching of index.html
.
Default value false
Path to local directory to sync from.
Default value .
Add a deploy
script alias to your package.json
file:
{
...
"scripts": {
...
"deploy": "deploy-aws-s3-cloudfront --bucket my-bucket"
}
}
Run yarn run deploy
to deploy.
If you need to pass user or environment-level options that you don't want committed into package.json
you can provide these at call-time, e.g. yarn run deploy --distribution abc123
.
Configuration for create-react-app projects
Pass the --react
option when deploying apps created using create-react-app
. This is shortcut for deploy-aws-s3-cloudfront --source ./build/ --cache-control-no-cache index.html
.
-
AWS S3 Sync (bundled with AWS CLI)
The
aws s3 sync
command uses the modification time to identify modified assets. This doesn't work well when building a project often involves regenerating files with fresh timestamps but identical content.This package will instead perform a checksum comparison to minimise the deployment payload. The MD5 checksum will be computed against local files then compared against the ETag of the corresponding remote objects.
-
For React apps, the
react-deploy-s3
provides similar behaviour to this package. However,react-deploy-s3
expects your AWS credentials to be passed in as command arguments and requires additional configuration to get set up. In contrast, this package defers authentication to the AWS SDK and therefore supports multiple authentication strategies (e.g. IAM roles, environment variables and profiles).Additionally,
react-deploy-s3
will purge everything from your S3 bucket before re-uploading the entire build directory. Here, however, deployments are incremental resulting in a smaller payload and minimal interruption. Likewise, this package will perform a more efficient CloudFront purge by executing an invalidation on the affected paths only, as opposed to a site-wide refresh as performed byreact-deploy-s3
.