Movatterモバイル変換


[0]ホーム

URL:


Uploading and copying objects using multipart upload in Amazon S3 - Amazon Simple Storage Service
DocumentationAmazon Simple Storage Service (S3)User Guide
Multipart upload processChecksums with multipart upload operationsConcurrent multipart upload operationsPrevent uploading objects with identical key names during multipart uploadMultipart upload and pricingAPI support for multipart uploadAWS Command Line Interface support for multipart uploadAWS SDK support for multipart uploadMultipart upload API and permissionsChecksums with multipart upload operations

Uploading and copying objects using multipart upload in Amazon S3

Multipart upload allows you to upload a single object to Amazon S3 as a set of parts. Each part is a contiguous portion of the object's data. You can upload these object parts independently, and in any order. For uploads, your updated AWS client automatically calculates a checksum of the object and sends it to Amazon S3 along with the size of the object as a part of the request. If transmission of any part fails, you can retransmit that part without affecting other parts. After all parts of your object are uploaded, Amazon S3 assembles them to create the object. It's a best practice to use multipart upload for objects that are 100 MB or larger instead of uploading them in a single operation.

Using multipart upload provides the following advantages:

We recommend that you use multipart upload in the following ways:

Multipart upload process

Multipart upload is a three-step process: You initiate the upload, upload the object parts, and—after you've uploaded all the parts—complete the multipart upload. Upon receiving the complete multipart upload request, Amazon S3 constructs the object from the uploaded parts, and you can access the object just as you would any other object in your bucket.

You can list all of your in-progress multipart uploads or get a list of the parts that you have uploaded for a specific multipart upload. Each of these operations is explained in this section.

Multipart upload initiation

When you send a request to initiate a multipart upload, make sure to specify a checksum type. Amazon S3 will then return a response with an upload ID, which is a unique identifier for your multipart upload. This upload ID is required when you upload parts, list parts, complete an upload, or stop an upload. If you want to provide metadata describing the object being uploaded, you must provide it in the request to initiate the multipart upload. Anonymous users cannot initiate multipart uploads.

Parts upload

When uploading a part, you must specify a part number in addition to the upload ID. You can choose any part number between 1 and 10,000. A part number uniquely identifies a part and its position in the object you are uploading. The part number that you choose doesn’t need to be in a consecutive sequence (for example, it can be 1, 5, and 14). Be aware that if you upload a new part using the same part number as a previously uploaded part, the previously uploaded part gets overwritten.

When you upload a part, Amazon S3 returns the checksum algorithm type with the checksum value for each part as a header in the response. For each part upload, you must record the part number and the ETag value. You must include these values in the subsequent request to complete the multipart upload. Each part will have its own ETag at the time of upload. However, once the multipart upload is complete and all parts are consolidated, all parts belong to one ETag as a checksum of checksums.

Multipart upload completion

When you complete a multipart upload, Amazon S3 creates an object by concatenating the parts in ascending order based on the part number. If any object metadata was provided in theinitiate multipart upload request, Amazon S3 associates that metadata with the object. After a successfulcomplete request, the parts no longer exist.

Yourcomplete multipart upload request must include the upload ID and a list of part numbers and their corresponding ETag values. The Amazon S3 response includes an ETag that uniquely identifies the combined object data. This ETag is not necessarily an MD5 hash of the object data.

When you provide a full object checksum during a multipart upload, the AWS SDK passes the checksum to Amazon S3, and S3 validates the object integrity server-side, comparing it to the received value. Then, S3 stores the object if the values match. If the two values don’t match, Amazon S3 fails the request with aBadDigest error. The checksum of your object is also stored in object metadata that you'll later use to validate an object's data integrity.

Sample multipart upload calls

For this example, assume that you're generating a multipart upload for a 100 GB file. In this case, you would have the following API calls for the entire process. There would be a total of 1,002 API calls.

Multipart upload listings

You can list the parts of a specific multipart upload or all in-progress multipart uploads. The list parts operation returns the parts information that you uploaded for a specific multipart upload. For each list parts request, Amazon S3 returns the parts information for the specified multipart upload, up to a maximum of 1,000 parts. If there are more than 1,000 parts in the multipart upload, you must send a series of list part requests to retrieve all of the parts. Note that the returned list of parts doesn't include parts that haven't finished uploading. Using thelist multipart uploads operation, you can obtain a list of multipart uploads that are in progress.

An in-progress multipart upload is an upload that you have initiated, but have not yet completed or stopped. Each request returns at most 1,000 multipart uploads. If there are more than 1,000 multipart uploads in progress, you must send additional requests to retrieve the remaining multipart uploads. Use the returned listing only for verification.

Checksums with multipart upload operations

When you upload an object to Amazon S3, you can specify a checksum algorithm for Amazon S3 to use. By default, the AWS SDK and S3 console use an algorithm for all object uploads, which you can override. If you’re using an older SDK and your uploaded object doesn’t have a specified checksum, Amazon S3 automatically uses the CRC-64/NVME (CRC64NVME) checksum algorithm. (This is also the recommended option for efficient data integrity verification.) When using CRC-64/NVME, Amazon S3 calculates the checksum of the full object after the multipart or single part upload is complete. The CRC-64/NVME checksum algorithm is used to calculate either a direct checksum of the entire object, or a checksum of the checksums, for each individual part.

After you upload an object to S3 using multipart upload, Amazon S3 calculates the checksum value for each part, or for the full object—and stores the values. You can use the S3 API or AWS SDK to retrieve the checksum value in the following ways:

For more information about how checksums work with multipart upload objects, seeChecking object integrity in Amazon S3.

For an end-to-end procedure that demonstrates how to upload an object using multipart upload with an additional checksum, seeTutorial: Upload an object through multipart upload and verify its data integrity.

Concurrent multipart upload operations

In a distributed development environment, it is possible for your application to initiate several updates on the same object at the same time. Your application might initiate several multipart uploads using the same object key. For each of these uploads, your application can then upload parts and send a complete upload request to Amazon S3 to create the object. When the buckets have S3 Versioning enabled, completing a multipart upload always creates a new version. When you initiate multiple multipart uploads that use the same object key in a versioning-enabled bucket, the current version of the object is determined by which upload started most recently (createdDate).

For example, you start aCreateMultipartUpload request for an object at 10:00 AM. Then, you submit a secondCreateMultipartUpload request for the same object at 11:00 AM. Because the second request was submitted the most recently, the object uploaded by the 11:00 AM request becomes the current version, even if the first upload is completed after the second one. For buckets that don't have versioning enabled, it's possible that any other request received between the time when the multipart upload is initiated and when it completes, the other request might take precedence.

Another example of when a concurrent multipart upload request can take precedence is if another operation deletes a key after you initiate a multipart upload with that key. Before you complete the operation, the complete multipart upload response might indicate a successful object creation without you ever seeing the object.

Prevent uploading objects with identical key names during multipart upload

You can check for the existence of an object in your bucket before creating it using a conditional write on upload operations. This can prevent overwrites of existing data. Conditional writes will validate that there is no existing object with the same key name already in your bucket while uploading.

You can use conditional writes forPutObject orCompleteMultipartUpload requests.

For more information about conditional requests see,Add preconditions to S3 operations with conditional requests.

Multipart upload and pricing

After you initiate a multipart upload, Amazon S3 retains all the parts until you either complete or stop the upload. Throughout its lifetime, you are billed for all storage, bandwidth, and requests for this multipart upload and its associated parts.

These parts are billed according to the storage class specified when the parts are uploaded. However, you will not be billed for these parts if they're uploaded to S3 Glacier Flexible Retrieval or S3 Glacier Deep Archive. In-progress multipart parts for a PUT request to the S3 Glacier Flexible Retrieval storage class are billed as S3 Glacier Flexible Retrieval staging storage at S3 Standard storage rates until the upload completes. In addition, bothCreateMultipartUpload andUploadPart are billed at S3 Standard rates. Only theCompleteMultipartUpload request is billed at the S3 Glacier Flexible Retrieval rate. Similarly, in-progress multipart parts for a PUT to the S3 Glacier Deep Archive storage class are billed as S3 Glacier Flexible Retrieval staging storage at S3 Standard storage rates until the upload completes, with only theCompleteMultipartUpload request charged at S3 Glacier Deep Archive rates.

If you stop the multipart upload, Amazon S3 deletes upload artifacts and all parts that you uploaded. You will not be billed for those artifacts. There are no early delete charges for deleting incomplete multipart uploads regardless of storage class specified. For more information about pricing, seeAmazon S3 pricing.

API support for multipart upload

The following sections in theAmazon Simple Storage Service API Reference describe the REST API for multipart upload.

For a multipart upload walkthrough that uses AWS Lambda functions, seeUploading large objects to Amazon S3 using multipart upload and transfer acceleration.

AWS Command Line Interface support for multipart upload

The following topics in the AWS Command Line Interface describe the operations for multipart upload.

AWS SDK support for multipart upload

You can use an AWS SDKs to upload an object in parts. For a list of AWS SDKs supported by API action see:

Multipart upload API and permissions

You must have the necessary permissions to use the multipart upload operations. You can use access control lists (ACLs), the bucket policy, or the user policy to grant individuals permissions to perform these operations. The following table lists the required permissions for various multipart upload operations when using ACLs, a bucket policy, or a user policy.

ActionRequired permissions

Create Multipart Upload

You must be allowed to perform thes3:PutObject action on an object to create a multipart upload request.

The bucket owner can allow other principals to perform thes3:PutObject action.

Initiate Multipart Upload

You must be allowed to perform thes3:PutObject action on an object to initiate a multipart upload.

The bucket owner can allow other principals to perform thes3:PutObject action.

Initiator

Container element that identifies who initiated the multipart upload. If the initiator is an AWS account, this element provides the same information as the Owner element. If the initiator is an IAM user, this element provides the user ARN and display name.

Upload Part

You must be allowed to perform thes3:PutObject action on an object to upload a part.

The bucket owner must allow the initiator to perform thes3:PutObject action on an object in order for the initiator to upload a part for that object.

Upload Part (Copy)

You must be allowed to perform thes3:PutObject action on an object to upload a part. Because you are uploading a part from an existing object, you must be alloweds3:GetObject on the source object.

For the initiator to upload a part for an object, the owner of the bucket must allow the initiator to perform thes3:PutObject action on the object.

Complete Multipart Upload

You must be allowed to perform thes3:PutObject action on an object to complete a multipart upload.

The bucket owner must allow the initiator to perform thes3:PutObject action on an object in order for the initiator to complete a multipart upload for that object.

Stop Multipart Upload

You must be allowed to perform thes3:AbortMultipartUpload action to stop a multipart upload.

By default, the bucket owner and the initiator of the multipart upload are allowed to perform this action as a part of IAM and S3 bucket polices. If the initiator is an IAM user, that user's AWS account is also allowed to stop that multipart upload. With VPC endpoint policies, the initiator of the multipart upload doesn't automatically gain the permission to perform thes3:AbortMultipartUpload action.

In addition to these defaults, the bucket owner can allow other principals to perform thes3:AbortMultipartUpload action on an object. The bucket owner can deny any principal the ability to perform thes3:AbortMultipartUpload action.

List Parts

You must be allowed to perform thes3:ListMultipartUploadParts action to list parts in a multipart upload.

By default, the bucket owner has permission to list parts for any multipart upload to the bucket. The initiator of the multipart upload has the permission to list parts of the specific multipart upload. If the multipart upload initiator is an IAM user, the AWS account controlling that IAM user also has permission to list parts of that upload.

In addition to these defaults, the bucket owner can allow other principals to perform thes3:ListMultipartUploadParts action on an object. The bucket owner can also deny any principal the ability to perform thes3:ListMultipartUploadParts action.

List Multipart Uploads

You must be allowed to perform thes3:ListBucketMultipartUploads action on a bucket to list multipart uploads in progress to that bucket.

In addition to the default, the bucket owner can allow other principals to perform thes3:ListBucketMultipartUploads action on the bucket.

AWS KMS Encrypt and Decrypt related permissions

To perform a multipart upload with encryption using an AWS Key Management Service (AWS KMS) KMS key, the requester must have the following permissions:

These permissions are required because Amazon S3 must decrypt and read data from the encrypted file parts before it completes the multipart upload. Thekms:Decrypt permission, and the server-side encryption with customer-provided encryption keys, are also required for you to obtain an object's checksum value. If you don't have these required permissions when you use theCompleteMultipartUpload API, the object is created without a checksum value.

If your IAM user or role is in the same AWS account as the KMS key, then validate that you have permissions on both the key and IAM policies. If your IAM user or role belongs to a different account than the KMS key, then you must have the permissions on both the key policy and your IAM user or role.

SSE-C (server-side encryption with customer-provided encryption keys)

When you use theCompleteMultipartUpload API, you must provide the SSE-C (server-side encryption with customer-provided encryption keys), or your object will be created without a checksum, and no checksum value is returned.

For information on the relationship between ACL permissions and permissions in access policies, seeMapping of ACL permissions and access policypermissions. For information about IAM users, roles, and best practices, seeIAM identities (users, user groups, and roles) in theIAM User Guide.

Checksums with multipart upload operations

There are three Amazon S3 APIs that are used to perform the actual multipart upload:CreateMultipartUpload,UploadPart, andCompleteMultipartUpload. The following table indicates which checksum headers and values must be provided for each of the APIs:

Checksum algorithmChecksum typeCreateMultipartUploadUploadPartCompleteMultipartUpoad

CRC-64/NVME (CRC64NVME)

Full objectRequired headers:

x-amz-checksum-algorithm

Optional headers:

x-amz-checksum-crc64nvme

Optional headers:

x-amz-checksum-algorithm

x-amz-crc64

CRC-32 (CRC32)

CRC 32-C (CRC32C)

Full object

Required headers:

x-amz-checksum-algorithm

x-amz-checksum-type

Optional headers:

x-amz-checksum-crc64nvme

Optional headers:

x-amz-checksum-algorithm

x-amz-crc32

x-amz-crc32c

CRC-32 (CRC32)

CRC-32C (CRC32C)

SHA-1 (SHA1)

SHA-256 (SHA256)

Composite

Required headers:

x-amz-checksum-algorithm

Required headers:

x-amz-checksum-crc32

x-amz-checksum-crc32c

x-amz-checksum-sha1

x-amz-checksum-sha256

Required headers:

All part-level checksums need to be included in theCompleteMultiPartUpload request.

Optional headers:

x-amz-crc32

x-amz-crc32c

x-amz-sha1

x-amz-sha256

Uploading objects
Configuring a lifecycle configuration to delete incomplete multipart uploads

[8]
ページ先頭

©2009-2025 Movatter.jp