“aws s3 cp” Command Examples

The aws s3 cp command is a part of the AWS Command Line Interface (CLI) and is used to copy local files or objects stored in Amazon S3 to another location, either locally or within Amazon S3 itself.

Here’s an overview of the aws s3 cp command and its functionality:

  • Copying Local Files to S3: The aws s3 cp command allows you to upload local files or directories to Amazon S3. You can specify the source file or directory on your local machine and provide the destination S3 bucket and key where the files should be uploaded.
  • Copying S3 Objects Locally: You can use the aws s3 cp command to download files or objects stored in Amazon S3 to your local machine. Simply specify the source S3 bucket and key, and provide the destination path on your local system where the files should be downloaded.
  • Copying Within S3: The aws s3 cp command also supports copying objects within Amazon S3 itself. You can specify the source S3 bucket and key as well as the destination bucket and key, allowing you to copy objects from one location to another within S3.
  • Recursive Copy: The aws s3 cp command provides an option to perform a recursive copy, allowing you to copy entire directories or folders and their contents. This is useful when you need to copy a large number of files or maintain the directory structure during the copy process.
  • Filtering Files: You can specify filters to include or exclude certain files or objects during the copy operation. This allows you to selectively copy files based on file extensions, prefixes, or other criteria.
  • Preserving Metadata: By default, the aws s3 cp command preserves the metadata (e.g., timestamps, permissions) of the source files or objects during the copy process. This ensures that the copied files retain the same attributes as the originals.

The aws s3 cp command provides a flexible and efficient way to copy files and objects between your local machine and Amazon S3, or within different locations in S3 itself. It is a powerful tool for managing data transfer to and from S3, enabling you to move, backup, and synchronize files with ease.

aws s3 cp Command Examples

1. Copy a file from local to a specific bucket:

# aws s3 cp /path/to/file s3://bucket_name/path/to/remote_file

2. Copy a specific S3 object into another bucket:

# aws s3 cp s3://bucket_name1/path/to/file s3://bucket_name2/path/to/target

3. Copy a specific S3 object into another bucket keeping the original name:

# aws s3 cp s3://bucket_name1//path/to/file s3:// bucket_name2

4. Copy S3 objects to a local directory recursively:

# aws s3 cp s3://bucket_name . --recursive

5. Display help:

# aws s3 cp help
Related Post