Copying an Object to a Bucket

You can copy an object from one of your buckets to another bucket that you own or to the bucket of another user provided you have the appropriate permissions. You can also copy an object from the bucket of another user to one of your buckets. For more information, see Access Control List (ACL) Reference.

You are the owner of the copy of the object, which is independent from the source one. You cannot change the key of the object once it is copied in the bucket. If you copy an object with the same name as another object already contained in the bucket, the object you upload replaces the former object. If the bucket versioning is enabled, this former object is conserved as a previous version. For more information, see Enabling or Disabling Bucket Versioning.

This action also returns an ETag element that you need to create a multipart-upload. For more information, see Creating a Multipart Upload.

Copying an Object to a Bucket Using AWS CLI

To copy an object to one of your buckets, use the copy-object command following this syntax:

Request sample
$ aws s3api copy-object \
    --profile YOUR_PROFILE \
    --key OBJECT \
    --bucket BUCKET \
    --acl private \
    --grant-full-control "id=USER_ID, id=USER_ID" \
    --grant-read "id=USER_ID, id=USER_ID" \
    --grant-read-acp "id=USER_ID, id=USER_ID" \
    --grant-write-acp "id=USER_ID, id=USER_ID" \

This command contains the following attributes that you need to specify:

  • (optional) profile: The named profile you want to use, created when configuring AWS CLI. For more information, see Installing and Configuring AWS CLI.

  • copy-source: The path to the object you want to copy.

  • key: The key for the new object.

    You can use the same prefix in the keys of several objects in the following format: prefix/key1, prefix/key2, and so on.

    This creates a virtual architecture in your bucket and enables you to retrieve your objects faster when listing them. For more information, see Listing the Objects of a Bucket.

  • bucket: The destination bucket.

    • When specifying new permissions, all the previous permissions are replaced. Therefore, you need to specify both the existing permissions that you want to keep (including for yourself) and the new permissions that you want to give in a single command.

    • If you are the owner of the bucket, you can lose your own permissions but not the ability to manage the ACL itself.

    For more information about existing permissions, see Getting Information About a Bucket ACL and Getting Information About an Object ACL.

  • (optional) acl: The permissions you grant for your object (private | public-read | public-read-write | authenticated-read | bucket-owner-read | bucket-owner-full-control).

  • (optional) grant-full-control: One or more IDs of users to whom you grant the full-control permission.

  • (optional) grant-read: One or more IDs of users to whom you grant the read permission.

  • (optional) grant-read-acp: One or more IDs of users to whom you grant the read-acp permission.

  • (optional) grant-write-acp: One or more IDs of users to whom you grant the write-acp permission.

  • endpoint: The endpoint corresponding to the Region you want to send the request to.

The copy-object command returns the following elements:

  • CopyObjectResult: Information about the copy. This element contains the following information about the copy:

    • LastModified: The date and time at which the object was copied.

    • ETag: The ETag of your object, that you need to use the multipart upload commands. For more information, see Creating a Multipart Upload.

Result Sample
    "CopyObjectResult": {
        "LastModified": "2017-01-05T13:28:34.676Z",
        "ETag": "fae4684b3d9544fababdd01e9a620584"
  • You can also perform this action using an s3 command following this syntax:

    $ aws s3 mv --profile $PROFILE s3://YOUR_SOURCE_BUCKET/YOUR_SOURCE_OBJECT s3://YOUR_TARGET_BUCKET --endpoint
  • You can also manage your object storage resources using s3cmd commands. For more information, see s3cmd.

Related Pages

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.