Syncs directories and S3 prefixes. Recursively copies new and updated files from the source directory to the destination. Only creates folders in the destination if they contain one or more files.
See ‘aws help’ for descriptions of global parameters.
sync
<LocalPath> <S3Uri> or <S3Uri> <LocalPath> or <S3Uri> <S3Uri>
[--dryrun]
[--quiet]
[--include <value>]
[--exclude <value>]
[--acl <value>]
[--follow-symlinks | --no-follow-symlinks]
[--no-guess-mime-type]
[--sse <value>]
[--sse-c <value>]
[--sse-c-key <value>]
[--sse-kms-key-id <value>]
[--sse-c-copy-source <value>]
[--sse-c-copy-source-key <value>]
[--storage-class <value>]
[--grants <value> [<value>...]]
[--website-redirect <value>]
[--content-type <value>]
[--cache-control <value>]
[--content-disposition <value>]
[--content-encoding <value>]
[--content-language <value>]
[--expires <value>]
[--source-region <value>]
[--only-show-errors]
[--no-progress]
[--page-size <value>]
[--ignore-glacier-warnings]
[--force-glacier-transfer]
[--request-payer <value>]
[--metadata <value>]
[--copy-props <value>]
[--metadata-directive <value>]
[--size-only]
[--exact-timestamps]
[--delete]
paths
(string)
--dryrun
(boolean)
Displays the operations that would be performed using the specified command without actually running them.
--quiet
(boolean)
Does not display the operations performed from the specified command.
--include
(string)
Don’t exclude files or objects in the command that match the specified pattern. See Use of Exclude and Include Filters for details.
--exclude
(string)
Exclude all files or objects from the command that matches the specified pattern.
--acl
(string)
Sets the ACL for the object when the command is performed. If you use this parameter you must have the “s3:PutObjectAcl” permission included in the list of actions for your IAM policy. Only accepts values of private
, public-read
, public-read-write
, authenticated-read
, aws-exec-read
, bucket-owner-read
, bucket-owner-full-control
and log-delivery-write
. See Canned ACL for details
--follow-symlinks
| --no-follow-symlinks
(boolean)
Symbolic links are followed only when uploading to S3 from the local filesystem. Note that S3 does not support symbolic links, so the contents of the link target are uploaded under the name of the link. When neither --follow-symlinks
nor --no-follow-symlinks
is specified, the default is to follow symlinks.
--no-guess-mime-type
(boolean)
Do not try to guess the mime type for uploaded files. By default the mime type of a file is guessed when it is uploaded.
--sse
(string)
Specifies server-side encryption of the object in S3. Valid values are AES256
and aws:kms
. If the parameter is specified but no value is provided, AES256
is used.
--sse-c
(string)
Specifies server-side encryption using customer provided keys of the the object in S3. AES256
is the only valid value. If the parameter is specified but no value is provided, AES256
is used. If you provide this value, --sse-c-key
must be specified as well.
--sse-c-key
(blob)
The customer-provided encryption key to use to server-side encrypt the object in S3. If you provide this value, --sse-c
must be specified as well. The key provided should not be base64 encoded.
--sse-kms-key-id
(string)
The customer-managed AWS Key Management Service (KMS) key ID that should be used to server-side encrypt the object in S3. You should only provide this parameter if you are using a customer managed customer master key (CMK) and not the AWS managed KMS CMK.
--sse-c-copy-source
(string)
This parameter should only be specified when copying an S3 object that was encrypted server-side with a customer-provided key. It specifies the algorithm to use when decrypting the source object. AES256
is the only valid value. If the parameter is specified but no value is provided, AES256
is used. If you provide this value, --sse-c-copy-source-key
must be specified as well.
--sse-c-copy-source-key
(blob)
This parameter should only be specified when copying an S3 object that was encrypted server-side with a customer-provided key. Specifies the customer-provided encryption key for Amazon S3 to use to decrypt the source object. The encryption key provided must be one that was used when the source object was created. If you provide this value, --sse-c-copy-source
be specified as well. The key provided should not be base64 encoded.
--storage-class
(string)
The type of storage to use for the object. Valid choices are: STANDARD | REDUCED_REDUNDANCY | STANDARD_IA | ONEZONE_IA | INTELLIGENT_TIERING | GLACIER | DEEP_ARCHIVE. Defaults to ‘STANDARD’
--grants
(string)
Grant specific permissions to individual users or groups. You can supply a list of grants of the form
--grants Permission=Grantee_Type=Grantee_ID [Permission=Grantee_Type=Grantee_ID ...]To specify the same permission type for multiple grantees, specify the permission as such as
--grants Permission=Grantee_Type=Grantee_ID,Grantee_Type=Grantee_ID,...Each value contains the following elements:
Permission
- Specifies the granted permissions, and can be set to read, readacl, writeacl, or full.
Grantee_Type
- Specifies how the grantee is to be identified, and can be set to uri or id.
Grantee_ID
- Specifies the grantee based on Grantee_Type. TheGrantee_ID
value can be one of:
uri - The group’s URI. For more information, see Who Is a Grantee?
id - The account’s canonical ID
For more information on Amazon S3 access control, see Access Control
--website-redirect
(string)
If the bucket is configured as a website, redirects requests for this object to another object in the same bucket or to an external URL. Amazon S3 stores the value of this header in the object metadata.
--content-type
(string)
Specify an explicit content type for this operation. This value overrides any guessed mime types.
--cache-control
(string)
Specifies caching behavior along the request/reply chain.
--content-disposition
(string)
Specifies presentational information for the object.
--content-encoding
(string)
Specifies what content encodings have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field.
--content-language
(string)
The language the content is in.
--expires
(string)
The date and time at which the object is no longer cacheable.
--source-region
(string)
When transferring objects from an s3 bucket to an s3 bucket, this specifies the region of the source bucket. Note the region specified by --region
or through configuration of the CLI refers to the region of the destination bucket. If --source-region
is not specified the region of the source will be the same as the region of the destination bucket.
--only-show-errors
(boolean)
Only errors and warnings are displayed. All other output is suppressed.
--no-progress
(boolean)
File transfer progress is not displayed. This flag is only applied when the quiet and only-show-errors flags are not provided.
--page-size
(integer)
The number of results to return in each response to a list operation. The default value is 1000 (the maximum allowed). Using a lower value may help if an operation times out.
--ignore-glacier-warnings
(boolean)
Turns off glacier warnings. Warnings about an operation that cannot be performed because it involves copying, downloading, or moving a glacier object will no longer be printed to standard error and will no longer cause the return code of the command to be 2
.
--force-glacier-transfer
(boolean)
Forces a transfer request on all Glacier objects in a sync or recursive copy.
--request-payer
(string)
Confirms that the requester knows that they will be charged for the request. Bucket owners need not specify this parameter in their requests. Documentation on downloading objects from requester pays buckets can be found at http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html
--metadata
(map)
A map of metadata to store with the objects in S3. This will be applied to every object which is part of this request. In a sync, this means that files which haven’t changed won’t receive the new metadata. key -> (string)
value -> (string)
Shorthand Syntax:
KeyName1=string,KeyName2=string
JSON Syntax:
{"string": "string"
...}
--copy-props
(string)
Determines which properties are copied from the source S3 object. This parameter only applies for S3 to S3 copies. Valid values are:
none
- Do not copy any of the properties from the source S3 object.
metadata-directive
- Copies the following properties from the source S3 object:content-type
,content-language
,content-encoding
,content-disposition
,cache-control
,--expires
, andmetadata
default
- The default value. Copies tags and properties covered under themetadata-directive
value from the source S3 object.In order to copy the appropriate properties for multipart copies, some of the options may require additional API calls if a multipart copy is involved. Specifically:
metadata-directive
may require additionalHeadObject
API calls.
default
may require additionalHeadObject
,GetObjectTagging
, andPutObjectTagging
API calls. Note this list of API calls may grow in the future in order to ensure multipart copies preserve the exact properties aCopyObject
API call would preserve.If you want to guarantee no additional API calls are made other than than the ones needed to perform the actual copy, set this option to
none
.
--metadata-directive
(string)
Sets the x-amz-metadata-directive
header for CopyObject operations. It is recommended to use the --copy-props
parameter instead to control copying of metadata properties. If --metadata-directive
is set, the --copy-props
parameter will be disabled and will have no affect on the transfer.
--size-only
(boolean)
Makes the size of each key the only criteria used to decide whether to sync from source to destination.
--exact-timestamps
(boolean)
When syncing from S3 to local, same-sized items will be ignored only when the timestamps match exactly. The default behavior is to ignore same-sized items unless the local version is newer than the S3 version.
--delete
(boolean)
Files that exist in the destination but not in the source are deleted during sync.
See ‘aws help’ for descriptions of global parameters.
The following sync
command syncs objects under a specified prefix and bucket to files in a local directory by
uploading the local files to s3. A local file will require uploading if the size of the local file is different than
the size of the s3 object, the last modified time of the local file is newer than the last modified time of the s3
object, or the local file does not exist under the specified bucket and prefix. In this example, the user syncs the
bucket mybucket
to the local current directory. The local current directory contains the files test.txt
and
test2.txt
. The bucket mybucket
contains no objects:
aws s3 sync . s3://mybucket
Output:
upload: test.txt to s3://mybucket/test.txt
upload: test2.txt to s3://mybucket/test2.txt
The following sync
command syncs objects under a specified prefix and bucket to objects under another specified
prefix and bucket by copying s3 objects. A s3 object will require copying if the sizes of the two s3 objects differ,
the last modified time of the source is newer than the last modified time of the destination, or the s3 object does not
exist under the specified bucket and prefix destination. In this example, the user syncs the bucket mybucket
to
the bucket mybucket2
. The bucket mybucket
contains the objects test.txt
and test2.txt
. The bucket
mybucket2
contains no objects:
aws s3 sync s3://mybucket s3://mybucket2
Output:
copy: s3://mybucket/test.txt to s3://mybucket2/test.txt
copy: s3://mybucket/test2.txt to s3://mybucket2/test2.txt
The following sync
command syncs files in a local directory to objects under a specified prefix and bucket by
downloading s3 objects. A s3 object will require downloading if the size of the s3 object differs from the size of the
local file, the last modified time of the s3 object is newer than the last modified time of the local file, or the s3
object does not exist in the local directory. Take note that when objects are downloaded from s3, the last modified
time of the local file is changed to the last modified time of the s3 object. In this example, the user syncs the
current local directory to the bucket mybucket
. The bucket mybucket
contains the objects test.txt
and
test2.txt
. The current local directory has no files:
aws s3 sync s3://mybucket .
Output:
download: s3://mybucket/test.txt to test.txt
download: s3://mybucket/test2.txt to test2.txt
The following sync
command syncs objects under a specified prefix and bucket to files in a local directory by
uploading the local files to s3. Because the --delete
parameter flag is thrown, any files existing under the
specified prefix and bucket but not existing in the local directory will be deleted. In this example, the user syncs
the bucket mybucket
to the local current directory. The local current directory contains the files test.txt
and
test2.txt
. The bucket mybucket
contains the object test3.txt
:
aws s3 sync . s3://mybucket --delete
Output:
upload: test.txt to s3://mybucket/test.txt
upload: test2.txt to s3://mybucket/test2.txt
delete: s3://mybucket/test3.txt
The following sync
command syncs objects under a specified prefix and bucket to files in a local directory by
uploading the local files to s3. Because the --exclude
parameter flag is thrown, all files matching the pattern
existing both in s3 and locally will be excluded from the sync. In this example, the user syncs the bucket mybucket
to the local current directory. The local current directory contains the files test.jpg
and test2.txt
. The
bucket mybucket
contains the object test.jpg
of a different size than the local test.jpg
:
aws s3 sync . s3://mybucket --exclude "*.jpg"
Output:
upload: test2.txt to s3://mybucket/test2.txt
The following sync
command syncs files under a local directory to objects under a specified prefix and bucket by
downloading s3 objects. This example uses the --exclude
parameter flag to exclude a specified directory
and s3 prefix from the sync
command. In this example, the user syncs the local current directory to the bucket
mybucket
. The local current directory contains the files test.txt
and another/test2.txt
. The bucket
mybucket
contains the objects another/test5.txt
and test1.txt
:
aws s3 sync s3://mybucket/ . --exclude "*another/*"
Output:
download: s3://mybucket/test1.txt to test1.txt
The following sync
command syncs files between two buckets in different regions:
aws s3 sync s3://my-us-west-2-bucket s3://my-us-east-1-bucket --source-region us-west-2 --region us-east-1
Sync to an S3 access point
The following sync
command syncs the current directory to the access point (myaccesspoint
):
aws s3 sync . s3://arn:aws:s3:us-west-2:123456789012:accesspoint/myaccesspoint/
Output:
upload: test.txt to s3://arn:aws:s3:us-west-2:123456789012:accesspoint/myaccesspoint/test.txt
upload: test2.txt to s3://arn:aws:s3:us-west-2:123456789012:accesspoint/myaccesspoint/test2.txt