terricain / aioboto3

Wrapper to use boto3 resources with the aiobotocore async backend
Apache License 2.0
698 stars 73 forks source link

Object.copy does not use `UploadPartCopy` for an s3<->s3 transfer #335

Closed vincer closed 1 month ago

vincer commented 2 months ago

Description

I'm doing an S3 to S3 copy of a large file (multiple GB) which should happen S3-side only using UploadPartCopy. Instead, it seems to be downloading and then reuploading the object using UploadPart. The end result is the same, but the download/upload is unnecessary, wasting bandwidth and takes longer.

Works as expected with boto3. https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3/object/copy.html

What I Did

        b = await s3.Bucket("destination")
        obj = await b.Object("key")
        await obj.copy({"Bucket": "source", "Key": "key"})

in boto3 it works as expected:

        b = s3.Bucket("destination")
        obj = b.Object("key")
        obj.copy({"Bucket": "source", "Key": "key"})
terricain commented 1 month ago

Yeah thats expected as when the code was written, UploadPartCopy did not exist :D

terricain commented 1 month ago

In v13.0.0 the s3.copy function has been rewritten and now utilises s3.copy_object or s3.upload_part_copy. FYI the default threshold in the S3 Transfer config object is 8MiB, s3.copy can copy objects up to 5GiB so bumping that for copies probably makes sense.

vincer commented 4 weeks ago

UploadPartCopy did not exist

That would do it! Thanks for the quick turnaround!