Copying an Existing Object as a Part

You can take an existing object (or a specified range of it) that is stored in one of your buckets and copy it as a single part of a new object, as part of the multipart upload process.

This enables you to repurpose data from an original object as part of a new one.

This approach leverages existing objects and allows you to avoid re-uploading data from your local environment by integrating them directly into new multipart uploads.

Copying an Existing Object as a Part Using AWS CLI (s3api)

Before you begin:

To copy an existing object as a part, use the upload-part-copy command following this syntax:

Request Sample
$ aws s3api upload-part-copy \
    --profile YOUR_PROFILE \
    --bucket DESTINATION_BUCKET \
    --copy-source SOURCE_BUCKET/OBJECT \
    --copy-source-if-match "\"b4fb2aaa356797d9a28bfc640a973720\"" \
    --copy-source-if-modified-since "2024-01-01T00:00:00Z" \
    --copy-source-if-none-match "\"b4fb2aaa356797d9a28bfc640a973720\"" \
    --copy-source-if-unmodified-since "2024-01-01T00:00:00Z"  \
    --copy-source-range bytes=O-9 \
    --key MULTIPART_UPLOAD \
    --part-number 1 \
    --upload-id 2~xrosnH8pbKTk3sjXijfGIUN1KAEM3Yc \
    --endpoint https://oos.eu-west-2.outscale.com

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.

  • bucket: The destination bucket in which the object will be copied as part of a multipart upload.

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

  • (optional) copy-source-if-match: Copies the object only if its ETag matches the ETag you specify for this attribute.

  • (optional) copy-source-if-modified-since: Copies the object only if it has been modified after the date and time you specify, in UTC format, for this attribute.

  • (optional) copy-source-if-none-match: Copies the object only if its ETag does not match the ETag you specify for this attribute.

  • (optional) copy-source-if-unmodified-since: Copies the object only if it has not been modified since the date and time you specify, in UTC format, for this attribute.

  • (optional) copy-source-range: Specifies which part of the object you want to copy. The formatting is bytes=first-last, where first and last are the starting and ending points of the part you want to copy. For example, bytes=O-9 means you are copying the first ten bytes of the object.

You can use this attribute only if the object you are copying is bigger than 5 MB.

  • key: The name given to the multipart upload you want to upload the copied object to.

  • part-number: The number for the part. The number must be a positive integer between 1 and 10000.

  • upload-id: The ID of the upload you received when initiating a multipart upload on the destination bucket. For more information, see Creating a Multipart Upload.

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

The upload-part-copy command returns the following element:

  • CopySourceVersionId: If bucket versioning was enabled on the source bucket, the version ID of the object being copied to the destination bucket. For more information, see Using Bucket Versioning.

  • CopyPartResult: Holds the response data for a part copied in a multipart upload.

    • ETag: The ETag for the part.

      Save this element carefully, as you will need it for further commands of multipart upload.

      In case of loss of this element, you can retrieve it. For more information, see Listing the Multipart Uploads of a Bucket.

    • LastModified: The date and time, in UTC format, at which the object was copied.

Result Sample
{
    "CopySourceVersionId": "aJavne0zwQtV00000000001I4j3QKItW",
    "CopyPartResult": {
        "ETag": "\"a367ed62e9d2353a3336d431fa4da763\"",
        "LastModified": "2024-02-28T09:22:19.123000+00:00"
    }
}

The object you copied as a part does not immediately appear in the destination bucket because the multipart upload process is not yet complete. Indeed, the parts you upload are not combined and visible as a single object in the destination bucket until you explicitly complete the multipart upload. For more information, see Completing a Multipart Upload.

Related Pages

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