Copying an object to a directory bucket - Amazon Simple Storage Service

Copying an object to a directory bucket

The copy operation creates a copy of an object that is already stored in Amazon S3. You can copy objects between directory buckets and general purpose buckets. You can also copy objects within a bucket and across buckets of the same type, for example, from directory bucket to directory bucket.

You can create a copy of object up to 5 GB in a single atomic operation. However, to copy an object that is greater than 5 GB, you must use the multipart upload API operations. For more information, see Using multipart uploads with directory buckets.

Permissions

To copy objects, you must have the following permissions:

  • To copy objects from one directory bucket to another directory bucket, you must have the s3express:CreateSession permission.

  • To copy objects from directory buckets to general purpose buckets, you must have the s3express:CreateSession permission and the s3:PutObject permission to write the object copy to the destination bucket.

  • To copy objects from general purpose buckets to directory buckets, you must have the s3express:CreateSession permission and s3:GetObject permission to read the source object that is being copied.

    For more information, see CopyObject in the Amazon Simple Storage Service API Reference.

Encryption

Amazon S3 automatically encrypts all new objects that are uploaded to an S3 bucket. The default encryption configuration of an S3 bucket is always enabled and is at a minimum set to server-side encryption with Amazon S3 managed keys (SSE-S3).

For directory buckets, only SSE-S3 is supported. For general purpose buckets, you can use SSE-S3 (the default), server-side encryption with AWS Key Management Service (AWS KMS) keys (SSE-KMS), dual-layer server-side encryption with AWS KMS keys (DSSE-KMS), or server-side encryption with customer-provided keys (SSE-C).

If you make a copy request that sets SSE-C, SSE-KMS, or DSSE-KMS parameters on a directory bucket as either the source or destination, the response returns an error,

Tags

Directory buckets don't support tags. If you copy an object that has tags from a general purpose bucket to a directory bucket, you receive an HTTP 501 (Not Implemented) response. For more information, see CopyObject in the Amazon Simple Storage Service API Reference.

ETags

Entity tags (ETags) for S3 Express One Zone are random alphanumeric strings and are not MD5 checksums. To help ensure object integrity, use additional checksums.

Additional checksums

S3 Express One Zone offers you the option to choose the checksum algorithm that is used to validate your data during upload or download. You can select one of the following Secure Hash Algorithms (SHA) or Cyclic Redundancy Check (CRC) data-integrity check algorithms: CRC32, CRC32C, SHA-1, and SHA-256. MD5-based checksums are not supported with the S3 Express One Zone storage class.

For more information, see S3 additional checksum best practices.

Supported features

For more information about which Amazon S3 features are supported for S3 Express One Zone, see How is S3 Express One Zone different?.

To copy an object from a general purpose bucket or a directory bucket to a directory bucket
  1. Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. In the left navigation pane, choose Buckets.

  3. Choose the bucket that you want to copy objects from:

    • To copy from a general purpose bucket, choose the General purpose buckets tab.

    • To copy from a directory bucket, choose the Directory buckets tab.

  4. Choose the general purpose bucket or directory bucket that contains the objects that you want to copy.

  5. Choose the Objects tab. On the Objects page, select the check box to the left of the names of the objects that you want to copy.

  6. On the Actions menu, choose Copy.

    The Copy page appears.

  7. Under Destination, choose Directory bucket for your destination type. To specify the destination path, choose Browse S3, navigate to the destination, and then choose the option button to the left of the destination. Choose Choose destination in the lower-right corner.

    Alternatively, enter the destination path.

  8. Under Checksums, choose whether you want to copy the objects with their existing checksum functions or replace the existing checksum functions with a new one. When you uploaded the objects, you had the option to specify the checksum algorithm that was used to verify data integrity. When copying the object, you have the option to choose a new function. If you dn't originally specify an additional checksum, you can use e Checksums section to add one.

    Note

    Even if you opt to use the same checksum function, your checksum value might change if the object is over 16 MB in size. The checksum value might change because of how checksums are calculated for multipart uploads. For more information about how the checksum might change when copying the object, see Using part-level checksums for multipart uploads.

    To change the checksum function, choose Replace with a new checksum function. Choose the new checksum function from the dropdown list. When the object is copied over, the new checksum is calculated and stored by using the specified algorithm.

  9. Choose Copy in the bottom-right corner. Amazon S3 copies your objects to the destination.

To copy an object from a directory bucket to a general purpose bucket
  1. Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. In the left navigation pane, choose Buckets.

  3. Choose the Directory buckets tab.

  4. Choose the directory bucket that contains the objects that you want to copy.

  5. Choose the Objects tab. On the Objects page, select the check box to the left of the names of the objects that you want to copy.

  6. On the Actions menu, choose Copy.

  7. Under Destination, choose General purpose bucket for your destination type. To specify the destination path, choose Browse S3, navigate to the destination, and choose the option button to the left of the destination. Choose Choose destination in the lower-right corner.

    Alternatively, enter the destination path.

  8. Under Checksums, choose whether you want to copy the objects with their existing checksum functions or replace the existing checksum functions with a new one. When you uploaded the objects, you had the option to specify the checksum algorithm that was used to verify data integrity. When copying the object, you have the option to choose a new function. If you didn't originally specify an additional checksum, you can use the Checksums section to add one.

    Note

    Even if you opt to use the same checksum function, your checksum value might change if the object is over 16 MB in size. The checksum value might change because of how checksums are calculated for multipart uploads. For more information about how the checksum might change when copying the object, see Using part-level checksums for multipart uploads.

    To change the checksum function, choose Replace with a new checksum function. Choose the new checksum function from the dropdown list. When the object is copied over, the new checksum is calculated and stored by using the specified algorithm.

  9. Choose Copy in the bottom-right corner. Amazon S3 copies your objects to the destination.

SDK for Java 2.x
public static void copyBucketObject (S3Client s3, String sourceBucket, String objectKey, String targetBucket) { CopyObjectRequest copyReq = CopyObjectRequest.builder() .sourceBucket(sourceBucket) .sourceKey(objectKey) .destinationBucket(targetBucket) .destinationKey(objectKey) .build(); String temp = ""; try { CopyObjectResponse copyRes = s3.copyObject(copyReq); System.out.println("Successfully copied " + objectKey +" from bucket " + sourceBucket +" into bucket "+targetBucket); } catch (S3Exception e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }

The following copy-object example command shows how you can use the AWS CLI to copy an object from one bucket to another bucket. You can copy objects between bucket types. To run this command, replace the user input placeholders with your own information.

aws s3api copy-object --copy-source bucket SOURCE_BUCKET/SOURCE_KEY_NAME --key TARGET_KEY_NAME --bucket TARGET_BUCKET_NAME

For more information, see copy-object in the AWS CLI Command Reference.