PUT Object - Copy
Description
This implementation of the PUT operation creates a copy of an object that is
already stored in Amazon S3. A PUT copy operation is the same as performing a
GET and then a PUT. Adding the request header,
x-amz-copy-source, makes the PUT operation copy the
source object into the destination bucket.
Note
You can store individual objects of up to 5 TB in Amazon S3. You create a copy of your object up to 5 GB in size in a single atomic operation using this API. However, for copying an object greater than 5 GB, you must use the multipart upload Upload Part - Copy API. For conceptual information, see Copy Object Using the REST Multipart Upload API in the Amazon Simple Storage Service Developer Guide.
When copying an object, you can preserve most of the metadata (default) or specify
new
metadata. However, the ACL is not preserved and is set to private for the user
making the request.
Important
Amazon S3 Transfer Acceleration does not support cross-region copies. If you request
a cross-region copy
using a Transfer Acceleration endpoint, you get a 400 Bad Request error. For more
information about transfer acceleration, see Transfer Acceleration in the
Amazon Simple Storage Service Developer Guide.
All copy requests must be authenticated and cannot contain a message body. Additionally, you must have READ access to the source object and WRITE access to the destination bucket. For more information, see REST Authentication.
To copy an object only under certain conditions, such as whether the ETag
matches or whether the object was modified before or after a specified date, use the
request
headers x-amz-copy-source-if-match, x-amz-copy-source-if-none-match,
x-amz-copy-source-if-unmodified-since, or
x-amz-copy-source-if-modified-since.
Note
All headers with the x-amz- prefix, including
x-amz-copy-source, must be signed.
You can use this operation to change the storage class of an object that is already
stored
in Amazon S3 using the x-amz-storage-class request header. For more information, go to
Storage Classes in
the Amazon Simple Storage Service Developer Guide.
The source object that you are copying can be encrypted or unencrypted. If the source object is encrypted, it can be encrypted by server-side encryption using AWS-managed encryption keys or by using a customer-provided encryption key. When copying an object, you can request that Amazon S3 encrypt the target object by using either the AWS-managed encryption keys or by using your own encryption key. You can do this regardless of the form of server-side encryption that was used to encrypt the source, or even if the source object was not encrypted. For more information about server-side encryption, see Using Server-Side Encryption in the Amazon Simple Storage Service Developer Guide.
A copy request might return an error when Amazon S3 receives the copy request or while
Amazon S3 is
copying the files. If the error occurs before the copy operation starts, you
receive a standard Amazon S3 error. If the error occurs during the copy operation, the
error response is embedded in the 200 OK response. This means that a 200
OK response can contain either a success or an error. Design your application to
parse the contents of the response and handle it appropriately.
If the copy is successful, you receive a response with information about the copied object.
Note
If the request is an HTTP 1.1 request, the response is chunk encoded. If it were not, it would not contain the content-length, and you would need to read the entire body.
The copy request charge is based on the storage class and region you specify for the destination object. For pricing information, see Amazon S3 Pricing.
Access Permissions
When copying an object, you can optionally specify the accounts or groups that should be granted specific permissions on the new object. There are two ways to grant the permissions using the request headers:
-
Specify a canned ACL with the
x-amz-aclrequest header. For more information, see Canned ACL in the Amazon Simple Storage Service Developer Guide. -
Specify access permissions explicitly with the
x-amz-grant-read,x-amz-grant-read-acp,x-amz-grant-write-acp, andx-amz-grant-full-controlheaders. These headers map to the set of permissions that Amazon S3 supports in an ACL. For more information, go to Access Control List (ACL) Overview in the Amazon Simple Storage Service Developer Guide.
Note
You can use either a canned ACL or specify access permissions explicitly. You cannot do both.
Requests
Syntax
PUT /destinationObjectHTTP/1.1 Host:destinationBucket.s3.amazonaws.com x-amz-copy-source: /source_bucket/sourceObjectx-amz-metadata-directive:metadata_directivex-amz-copy-source-if-match:etagx-amz-copy-source-if-none-match:etagx-amz-copy-source-if-unmodified-since:time_stampx-amz-copy-source-if-modified-since:time_stamp<request metadata> Authorization:authorization string(see Authenticating Requests (AWS Signature Version 4)) Date:date
Note
The syntax shows only some of the request headers. For a complete list, see the Request Headers section.
Request Parameters
This implementation of the operation does not use request parameters.
Request Headers
This implementation of the operation can use the following request headers in addition to the request headers common to all operations. Request headers are limited to 8 KB in size. For more information, see Common Request Headers.
| Name | Description | Required |
|---|---|---|
x-amz-copy-source |
The name of the source bucket and key name of the source object, separated by a slash (/). Type: String Default: None Constraints: This string must be URL-encoded. Additionally, the source bucket must be valid and you must have READ access to the valid source object. If the source object is archived in Amazon Glacier (the storage class of the object
is |
Yes |
x-amz-metadata-directive |
Specifies whether the metadata is copied from the source object or is replaced with metadata provided in the request.
Type: String Default: Valid values: Constraints: Values other than For information on supported metadata, see Common Request Headers |
No |
x-amz-copy-source-if-match |
Copies the object if its entity tag ( For more information, see Consideration 1 after this table. Type: String Default: None Constraints: This header can be used with
|
No |
x-amz-copy-source-if-none-match |
Copies the object if its entity tag ( For more information, see Consideration 1 after this table. Type: String Default: None Constraints: This header can be used with
|
No |
x-amz-copy-source-if-unmodified-since |
Copies the object if it hasn't been modified since the specified time. Otherwise, the request returns a 412 HTTP status code error (failed precondition). For more information, see Consideration 1 after this table. Type: String Default: None Constraints: This must be a valid HTTP date. This header can be used with
|
No |
x-amz-copy-source-if-modified-since |
Copies the object if it has been modified since the specified time; otherwise, the request returns a 412 HTTP status code error (failed condition). For more information, see Consideration 2 after this table. Type: String Default: None Constraints: This must be a valid HTTP date. This header can be used with
|
No |
x-amz-storage-class
|
If you don't specify this header, Amazon S3 uses Standard, the default, for the storage class. Amazon S3 supports other storage classes. For more information, see Storage Classes in the Amazon Simple Storage Service Developer Guide. Type: Enum Default: Valid Values: Constraints: You cannot specify |
No |
x-amz-tagging-directive |
Specifies whether the object tags are copied from the source object or replaced with tags provided in the request.
If you don't specify a tagging directive, Amazon S3 copies tags by default. If the tagging directive is REPLACE, you specify any tags in url format in the
If the tagging directive is REPLACE, but you don't specify the
Type: String Default: Valid values: Constraints: Values other than |
No |
x-amz-website-redirect-location
|
If the bucket is configured as a website, redirects requests for this object to another object in the same bucket or to an external URL. Amazon S3 stores the value of this header in the object metadata. For information about object metadata, see Object Key and Metadata. In the following example, the request header sets the redirect to an object (anotherPage.html) in the same bucket:
In the following example, the request header sets the object redirect to another website:
For more information about website hosting in Amazon S3, see Hosting Websites on Amazon S3 and How to Configure Website Page Redirects in the Amazon Simple Storage Service Developer Guide. Type: String Default: None Constraints: The value must be prefixed by, "/", "http://" or "https://". The length of the value is limited to 2 K. |
No |
Consider the following when using request headers:
-
Consideration 1 – If both the
x-amz-copy-source-if-matchandx-amz-copy-source-if-unmodified-sinceheaders are present in the request and evaluate as follows, Amazon S3 returns200 OKand copies the data:x-amz-copy-source-if-matchcondition evaluates totruex-amz-copy-source-if-unmodified-sincecondition evaluates tofalse -
Consideration 2 – If both of the
x-amz-copy-source-if-none-matchandx-amz-copy-source-if-modified-sinceheaders are present in the request and evaluate as follows, Amazon S3 returns the412 Precondition Failedresponse code:x-amz-copy-source-if-none-matchcondition evaluates tofalsex-amz-copy-source-if-modified-sincecondition evaluates to true
Server-Side- Encryption-Specific Request Headers
To encrypt the target object, you must provide the appropriate encryption-related request headers. The one you use depends on whether you want to use AWS-managed encryption keys or provide your own encryption key:
-
To encrypt the target object using server-side encryption with an AWS-managed encryption key, provide the following request headers, as appropriate.
Name Description Required x-amz-server-side-encryptionSpecifies a server-side encryption algorithm to use when Amazon S3 creates an object.
Type: String
Valid Value:
aws:kms,AES256Yes x-amz-server-side-encryption-aws-kms-key-idIf the
x-amz-server-side-encryptionheader is present and has the value ofaws:kms, this header specifies the ID of the AWS Key Management Service (AWS KMS) master encryption key that was used for the object.Type: String
Yes, if the value of x-amz-server-side-encryptionisaws:kmsx-amz-server-side-encryption-contextIf
x-amz-server-side-encryptionis present and its value isaws:kms, this header specifies the encryption context for the object. The value of this header is a base64-encoded UTF-8 string holding JSON with the encryption context key-value pairs.Type: String
No Note
If you specify
x-amz-server-side-encryption:aws:kms, but don't providex-amz-server-side- encryption-aws-kms-key-id, Amazon S3 uses the default AWS KMS key to protect the data.Important
All GET and PUT requests for an object protected by AWS KMS fail if you don't make them with SSL or by using SigV4.
For more information on Server-Side Encryption with Amazon KMS-Managed Keys (SSE-KMS), see Protecting Data Using Server-Side Encryption with AWS KMS-Managed Keys in the Amazon Simple Storage Service Developer Guide.
-
To encrypt the target object using server-side encryption with an encryption key that you provide, use the following headers.
Name Description Required x-amz-server-side-encryption-customer-algorithmSpecifies the algorithm to use to when encrypting the object.
Type: String
Default: None
Valid Value:
AES256Constraints: Must be accompanied by valid
x-amz-server-side-encryption-customer-keyandx-amz-server-side-encryption-customer-key-MD5headers.Yes x-amz-server-side-encryption-customer-keySpecifies the customer-provided base64-encoded encryption key for Amazon S3 to use to encrypt data. Amazon S3 uses this value to store the object and then discards it. Amazon does not store the encryption key. The key must be appropriate for use with the algorithm specified in the
x-amz-server-side-encryption-customer-algorithmheader.Type: String
Default: None
Constraints: Must be accompanied by valid
x-amz-server-side-encryption-customer-algorithmandx-amz-server-side-encryption-customer-key-MD5headers.Yes x-amz-server-side-encryption-customer-key-MD5Specifies the base64-encoded 128-bit MD5 digest of the encryption key according to RFC 1321. Amazon S3 uses this header as a message integrity check to ensure that the encryption key was transmitted without error.
Type: String
Default: None
Constraints: Must be accompanied by valid
x-amz-server-side-encryption-customer-algorithmandx-amz-server-side-encryption-customer-keyheaders.Yes -
If the source object is encrypted using server-side encryption with customer-provided encryption keys, you must use the following headers.
Name Description Required x-amz-copy-source-server-side-encryption-customer-algorithmSpecifies the algorithm to use when decrypting the source object.
Type: String
Default: None
Valid Value:
AES256Constraints: Must be accompanied by valid
x-amz-copy-source-server-side-encryption-customer-keyandx-amz-copy-source-server-side-encryption-customer-key-MD5headers.Yes x-amz-copy-source-server-side-encryption-customer-keySpecifies the customer-provided base64-encoded encryption key for Amazon S3 to use to decrypt the source object. After the copy operation, Amazon S3 discards this key. The encryption key provided in this header must be one that was used when the source object was created.
Type: String
Default: None
Constraints: Must be accompanied by valid
x-amz-copy-source-server-side-encryption-customer-algorithmandx-amz-copy-source-server-side-encryption-customer-key-MD5headers.Yes x-amz-copy-source-server-side-encryption-customer-key-MD5Specifies the base64-encoded 128-bit MD5 digest of the encryption key according to RFC 1321. Amazon S3 uses this header for a message integrity check to ensure that the encryption key was transmitted without error.
Type: String
Default: None
Constraints: Must be accompanied by valid
x-amz-copy-source-server-side-encryption-customer-algorithmandx-amz-copy-source-server-side-encryption-customer-keyheaders.Yes For more information on Server-Side Encryption with Customer-Provided Encryption Keys (SSE-C), see Protecting Data Using Server-Side Encryption with Customer-Provided Encryption Keys (SSE-C) in the Amazon Simple Storage Service Developer Guide.
Access-Control-List-ACL)-Specific Request Headers
You also can use the following access control–related headers with this operation. By default, all objects are private. Only the owner has full access control. When adding a new object, you can grant permissions to individual AWS accounts or to predefined groups defined by Amazon S3. These permissions are then added to the Access Control List (ACL) on the object. For more information, see Using ACLs. With this operation, you can grant access permissions using one of the following two methods:
-
Specify a canned ACL — Amazon S3 supports a set of predefined ACLs, known as canned ACLs. Each canned ACL has a predefined set of grantees and permissions. For more information, see Canned ACL.
Name Description Required x-amz-aclThe canned ACL to apply to the object.
Type: String
Default: private
Valid Values:
private | public-read | public-read-write | aws-exec-read | authenticated-read | bucket-owner-read | bucket-owner-full-controlConstraints: None
No
-
Specify access permissions explicitly — To explicitly grant access permissions to specific AWS accounts or groups, use the following headers. Each header maps to specific permissions that Amazon S3 supports in an ACL. For more information, see Access Control List (ACL) Overview. In the header, you specify a list of grantees who get the specific permission.
Name Description Required x-amz-grant-readGives the grantee permissions to read the object data and its metadata.
Type: String
Default: None
Constraints: None
No x-amz-grant-writeNot applicable. This header applies only when granting access permissions on a bucket.
Type: String
Default: None
Constraints: None
No x-amz-grant-read-acpGives the grantee permissions to read the object ACL.
Type: String
Default: None
Constraints: None
No x-amz-grant-write-acpGives the grantee permissions to write the ACL for the applicable object.
Type: String
Default: None
Constraints: None
No x-amz-grant-full-controlGives the grantee READ, READ_ACP, and WRITE_ACP permissions on the object.
Type: String
Default: None
Constraints: None
No
You specify each grantee as a type=value pair, where the type is one of
the following:
-
emailAddress – if the value specified is the email address of an AWS account
-
id – if the value specified is the canonical user ID of an AWS account
-
uri – if you are granting permissions to a predefined group.
For example, the following x-amz-grant-read header grants the AWS
accounts identified by email addresses permissions to read object data and its
metadata:
x-amz-grant-read: emailAddress="xyz@amazon.com", emailAddress="abc@amazon.com"
Request Elements
This implementation of the operation does not use request elements.
Responses
Response Headers
This implementation of the operation can include the following response headers in addition to the response headers common to all responses. For more information, see Common Response Headers.
| Name | Description |
|---|---|
x-amz-expiration
|
If an Type: String |
x-amz-copy-source-version-id |
Version of the source object that was copied. Type: String |
x-amz-server-side-encryption
|
If you specified server-side encryption either with an encryption key managed by AWS KMS or Amazon S3 in your copy request, the response includes this header. It confirms the encryption algorithm that Amazon S3 used to encrypt the object. Type: String |
x-amz-server-side-encryption-aws-kms-key-id
|
If the Type: String |
x-amz-server-side-encryption-customer-algorithm
|
If server-side encryption with customer-provided encryption keys (SSE-C) encryption was requested, the response includes this header, which confirms the encryption algorithm used for the destination object. Type: String Valid values: |
x-amz-server-side-encryption-customer-key-MD5
|
If SSE-C encryption was requested, the response includes this header to verify the integrity of the roundtrip message of the customer-provided encryption key that was used to encrypt the destination object. Type: String |
x-amz-storage-class |
Provides information about the object's storage class. Amazon S3 returns this
header for all objects except For more information, see Storage Classes in Amazon Simple Storage Service Developer Guide. Type: String Default: None |
x-amz-version-id |
Version of the copied object in the destination bucket. Type: String |
Response Elements
| Name | Description |
|---|---|
CopyObjectResult
|
Container for all response elements. Type: Container Ancestor: None |
ETag
|
Returns the Type: String Ancestor: |
LastModified
|
Returns the date that the object was last modified. Type: String Ancestor: |
Special Errors
This implementation of the operation does not return special errors. For general information about Amazon S3 errors and a list of error codes, see Error Responses.
Examples
Sample Request
This example copies my-image.jpg into the bucket
bucket, with the key name my-second-image.jpg.
PUT /my-second-image.jpg HTTP/1.1 Host: bucket.s3.amazonaws.com Date: Wed, 28 Oct 2009 22:32:00 GMT x-amz-copy-source: /bucket/my-image.jpg Authorization:authorization string
Sample Response
HTTP/1.1 200 OK x-amz-id-2: eftixk72aD6Ap51TnqcoF8eFidJG9Z/2mkiDFu8yU9AS1ed4OpIszj7UDNEHGran x-amz-request-id: 318BC8BC148832E5 x-amz-copy-source-version-id: 3/L4kqtJlcpXroDTDmJ+rmSpXd3dIbrHY+MTRCxf3vjVBH40Nr8X8gdRQBpUMLUo x-amz-version-id: QUpfdndhfd8438MNFDN93jdnJFkdmqnh893 Date: Wed, 28 Oct 2009 22:32:00 GMT Connection: close Server: AmazonS3 <CopyObjectResult> <LastModified>2009-10-28T22:32:00</LastModified> <ETag>"9b2cf535f27731c974343645a3985328"</ETag> </CopyObjectResult>
x-amz-version-id returns the version ID of the object in the destination
bucket. x-amz-copy-source-version-id returns the version ID of the source
object.
Sample Request: Copying a Specified Version of an Object
The following request copies the my-image.jpg key with the specified
version ID, copies it into the bucket bucket, and gives it the
my-second-image.jpg key.
PUT /my-second-image.jpg HTTP/1.1 Host: bucket.s3.amazonaws.com Date: Wed, 28 Oct 2009 22:32:00 GMT x-amz-copy-source: /bucket/my-image.jpg?versionId=3/L4kqtJlcpXroDTDmJ+rmSpXd3dIbrHY+MTRCxf3vjVBH40Nr8X8gdRQBpUMLUo Authorization:authorization string
Success Response: Copying a Versioned Object into a Version-enabled Bucket
The following response shows that an object was copied into a target bucket where versioning is enabled.
HTTP/1.1 200 OK x-amz-id-2: eftixk72aD6Ap51TnqcoF8eFidJG9Z/2mkiDFu8yU9AS1ed4OpIszj7UDNEHGran x-amz-request-id: 318BC8BC148832E5 x-amz-version-id: QUpfdndhfd8438MNFDN93jdnJFkdmqnh893 x-amz-copy-source-version-id: 09df8234529fjs0dfi0w52935029wefdj Date: Wed, 28 Oct 2009 22:32:00 GMT Connection: close Server: AmazonS3 <?xml version="1.0" encoding="UTF-8"?> <CopyObjectResult> <LastModified>2009-10-28T22:32:00</LastModified> <ETag>"9b2cf535f27731c974343645a3985328"</ETag> </CopyObjectResult>
Success Response: Copying a Versioned Object into a Version-suspended Bucket
The following response shows that an object was copied into a target bucket where
versioning is suspended. The parameter <VersionId> does not appear.
HTTP/1.1 200 OK x-amz-id-2: eftixk72aD6Ap51TnqcoF8eFidJG9Z/2mkiDFu8yU9AS1ed4OpIszj7UDNEHGran x-amz-request-id: 318BC8BC148832E5 x-amz-copy-source-version-id: 3/L4kqtJlcpXroDTDmJ+rmSpXd3dIbrHY+MTRCxf3vjVBH40Nr8X8gdRQBpUMLUo Date: Wed, 28 Oct 2009 22:32:00 GMT Connection: close Server: AmazonS3 <?xml version="1.0" encoding="UTF-8"?> <CopyObjectResult> <LastModified>2009-10-28T22:32:00</LastModified> <ETag>"9b2cf535f27731c974343645a3985328"</ETag> </CopyObjectResult>
Sample: Copy from Unencrypted Object to an Object Encrypted with Server-side Encryption with Customer-provided Encryption Keys
The following example specifies the HTTP PUT header to copy an unencrypted
object to an object encrypted with server-side encryption with customer-provided encryption
keys (SSE-C).
PUT /exampleDestinationObject HTTP/1.1 Host: example-destination-bucket.s3.amazonaws.com x-amz-server-side-encryption-customer-algorithm: AES256 x-amz-server-side-encryption-customer-key: Base64(YourKey) x-amz-server-side-encryption-customer-key-MD5 : Base64(MD5(YourKey)) x-amz-metadata-directive: metadata_directive x-amz-copy-source: /example_source_bucket/exampleSourceObject x-amz-copy-source-if-match:etagx-amz-copy-source-if-none-match:etagx-amz-copy-source-if-unmodified-since:time_stampx-amz-copy-source-if-modified-since:time_stamp<request metadata> Authorization:authorization string(see Authenticating Requests (AWS Signature Version 4)) Date:date
Sample: Copy from an Object Encrypted with SSE-C to an Object Encrypted with SSE-C
The following example specifies the HTTP PUT header to copy an object
encrypted with server-side encryption with customer-provided encryption keys to an
object encrypted with server-side encryption with customer-provided encryption keys
for key rotation.
PUT /exampleDestinationObject HTTP/1.1 Host: example-destination-bucket.s3.amazonaws.com x-amz-server-side-encryption-customer-algorithm: AES256 x-amz-server-side-encryption-customer-key: Base64(NewKey) x-amz-server-side-encryption-customer-key-MD5: Base64(MD5(NewKey)) x-amz-metadata-directive: metadata_directive x-amz-copy-source: /source_bucket/sourceObject x-amz-copy-source-if-match:etagx-amz-copy-source-if-none-match:etagx-amz-copy-source-if-unmodified-since:time_stampx-amz-copy-source-if-modified-since:time_stampx-amz-copy-source-server-side-encryption-customer-algorithm: AES256 x-amz-copy-source-server-side-encryption-customer-key: Base64(OldKey) x-amz-copy-source-server-side-encryption-customer-key-MD5: Base64(MD5(OldKey)) <request metadata> Authorization:authorization string(see Authenticating Requests (AWS Signature Version 4)) Date:date


