LinuxCommandLibrary

aws-s3-mv

Move objects between S3 locations

TLDR

Move a file from local to a specified bucket

$ aws s3 mv [path/to/local_file] s3://[bucket_name]/[path/to/remote_file]
copy

Move a specific S3 object into another bucket
$ aws s3 mv s3://[bucket_name1]/[path/to/file] s3://[bucket_name2]/[path/to/target]
copy

Move a specific S3 object into another bucket keeping the original name
$ aws s3 mv s3://[bucket_name1]/[path/to/file] s3://[bucket_name2]
copy

Display help
$ aws s3 mv help
copy

SYNOPSIS

aws s3 mv <source> <target> [options]

Examples:
aws s3 mv localfile.txt s3://mybucket/remote/path/
aws s3 mv s3://mybucket/oldkey s3://mybucket/newkey
aws s3 mv s3://mybucket/prefix/ s3://anotherbucket/newprefix/ --recursive

PARAMETERS

source
    The path to the source object or directory. Can be a local filesystem path or an S3 URI (e.g., s3://bucket/key).

target
    The path to the destination object or directory. Can be a local filesystem path or an S3 URI (e.g., s3://bucket/key).

--recursive
    Recursively moves files/objects under the specified source path. Required for directory-like operations.

--exclude pattern
    Don't include files matching the given pattern during a recursive operation.

--include pattern
    Only include files matching the given pattern during a recursive operation. Takes precedence over --exclude.

--dryrun
    Displays the operations that would be performed without actually executing them.

--grants permissions
    Sets ACLs for the destination object. Format: Permission=GranteeType=Grantee[,GranteeType=Grantee]...

--acl acl_type
    Specifies a canned ACL for the destination object (e.g., private, public-read, bucket-owner-full-control).

--storage-class class
    Sets the storage class for the destination object (e.g., STANDARD, REDUCED_REDUNDANCY, GLACIER, DEEP_ARCHIVE).

--sse
    Enables server-side encryption with S3-managed keys.

--sse-kms-key-id key_id
    Enables server-side encryption with AWS KMS-managed keys, specifying the KMS key ID.

--force
    When moving from S3 to local, overwrite existing local files without prompting.

DESCRIPTION

The aws s3 mv command, part of the AWS Command Line Interface (CLI), facilitates the movement of objects within Amazon S3 or between Amazon S3 and the local filesystem. Conceptually, it performs a copy operation from the source to the destination, followed by the deletion of the original source object. This utility is powerful for reorganizing data within your S3 environment, migrating files to/from S3, or renaming objects.

When moving objects between S3 locations, the command typically handles large files efficiently using multipart uploads. It supports recursive operations for moving entire directories (S3 prefixes) and offers various options for fine-grained control over the move process, including specifying access control lists (ACLs), storage classes, and server-side encryption settings. It's an indispensable tool for managing your cloud storage resources.

CAVEATS

The aws s3 mv command performs a copy and then a delete. This means that if the delete operation fails for any reason (e.g., permissions, eventual consistency issues), the source object might still exist, leading to duplicates. It's crucial to verify the operation's success. Cross-region moves are generally supported but might incur higher data transfer costs. For large-scale data migrations or complex synchronization needs, consider using AWS DataSync or other specialized services.

PERMISSIONS

The AWS credentials configured for your CLI must have appropriate IAM permissions for both source (read and delete) and destination (write) S3 buckets and objects. Lack of permissions can cause the command to fail.

COST IMPLICATIONS

Moving objects between S3 buckets, especially across regions, can incur data transfer costs. Be mindful of these costs, particularly for large datasets.

HISTORY

The aws s3 mv command is an integral part of the AWS Command Line Interface (CLI), which was first released in 2013, providing a unified tool to manage AWS services from the command line. The S3 subcommands, including mv, have been fundamental since early versions, offering essential capabilities for interacting with Amazon S3. Its development has focused on improving performance, especially for large file transfers (multipart uploads), and incorporating new S3 features like various storage classes and encryption options, making it a robust and widely used utility for S3 management.

SEE ALSO

aws s3 cp(1), aws s3 sync(1), aws s3 rm(1), aws configure(1), aws(1)

Copied to clipboard