AWS CLI S3 Cheatsheet - s3 sync

Search for a command to run...

No comments yet. Be the first to comment.
The ls command can be used for listing S3 buckets or objects inside a bucket. When used to list objects, the command will show you only objects in the current prefix. List all buckets ~ aws s3 ls 2019-12-15 16:31:53 testbucket1 2020-03-11 14:44:32 te...
Intro When working on a monolith and traffic increases, you might decide to start caching to manage the new volume. If your system is modern or small, you have several caching strategies: Handle the caching logic within the code by integrating somet...
A tutorial using the AWS console

A Step Function Distributed Map and Lambda Demo

Amazon CloudFront CloudFront is Amazon’s offer for Content Delivery Network. The CDN is composed of a globally distributed set of caching servers that provide low latency and high throughput all around the world. The network is based on more than 300...

The AWS CLI sync command is a powerful tool for copying new and updated files between a source and destination, with at least one of them being an S3 Bucket.
This command can also be used to perform sync between S3 Buckets without the need to transit files on a local machine. In this article, we will explore the various options available with the sync command, including the exclude and include options, the delete option, and the dry run option. We will also discuss how to use a specific storage class when uploading files to S3.
#From local to S3
~ aws s3 sync . s3://my-test-bucket
#From S3 to local
~ aws s3 sync s3://my-test-bucket .
# From S3 to S3
~ aws s3 sync s3://my-test-bucket s3://my-copy-test-bucket
The --exclude option in the AWS CLI sync command can be used to exclude files or objects from the sync based on specific patterns. This option allows users to exclude files based on their file extension, file name, or path. Users can also use the --exclude option multiple times to exclude multiple patterns.
~ aws s3 sync . s3://my-test-bucket --exclude "*.jpg"
Exclude a single large file:
~ aws s3 sync . s3://my-test-bucket --exclude "mydirectory/large-file.tar"
In addition, the --exclude option can be used in combination with the --include option to fine-tune file selection. This allows users to include specific files or objects while excluding others based on specific patterns.
aws s3 sync . s3://my-test-bucket --exclude "*" --include ".png" --include ".jpg"
The delete option in the AWS CLI sync command is used to remove files that exist in the destination but not in the source. This is a useful feature for keeping the destination in sync with the source and ensuring that outdated files are removed.
~ aws s3 sync --delete . s3://my-test-bucket
delete: s3://my-test-bucket/testfile1
The --dryrun option in the AWS CLI sync command allows users to preview the operation that would be executed without actually running it. This is a useful feature for testing and verifying your command before running it to ensure that it will perform the desired action.
~ aws s3 sync --dryrun --delete . s3://my-test-bucket
(dryrun) delete: s3://my-test-bucket/testfile1
The storage class option in the AWS CLI sync command allows users to specify a specific storage class when uploading files to S3.
This can be useful in situations where certain files require a different storage class than the default. For example, if a user needs to store infrequently accessed files, they can use the --storage-class option to specify the STANDARD_IA class.
~ aws s3 sync --storage-class "STANDARD_IA" . s3://my-test-bucket