question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document difference between S3 object `copy` vs `copy_from` vs `copy_object`

See original GitHub issue

s3.Object has methods copy and copy_from.

Based on the name, I assumed that copy_from would copy from some other key into the key (and bucket) of this s3.Object. Therefore I assume that the other copy function would to the opposite. i.e. copy from this s3.Object to another object. Or maybe the two are the other way around.

But after reading the docs for both, it looks like they both do the same thing. They both copy from another object into this object. Is that correct? What’s the point of having two functions that copy in the same direction?

What I want is to copy the existing s3.Object into a different path. I don’t want to have to manually instantiate a second s3.Object instance in python, and then pass the bucket and key manually from the first.

i.e. what’s the easiest way to copy s3://bucketA/pathA.txt to s3://bucketB/pathB.txt, if I already have s3.Object('bucketA','pathA.txt')?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
stobrien89commented, Nov 2, 2021

Hi @mdavis-xyz,

I thought initially this was a special case where the meta client was needed and that’s why it was documented, but that doesn’t appear to be the case— seems to work fine on a standard client as well. And yes, the meta client is just a way to access a service’s client from a resource instantiation.

Correct, copy_from is basically S3’s copy_object, which is single-threaded and copy is the multi-threaded, multi-part copy from s3Transfer.

3reactions
mdavis-xyzcommented, Oct 21, 2021

Can we add a new copy method to s3.Object? One that copies from this object to another?

It seems silly to bother having high-level resources, but then to copy you have to extract the low level client from the service resource or object resource, and then extract not one but two identifiers from the high level resource to pass to the low level call, in a way that is inconsistent with the way that the destination object is passed to the call. This is quite clunky and verbose.

We should be able to do:

obj.copy_to(destinationKey=key, destinationBucket=bucket_name)

but default the destination bucket to the source bucket if omitted:

obj.copy_to(destinationKey=key)

And also:

bucket.copy(sourceKey=key1, destinationKey=key2) # copy within bucket
Read more comments on GitHub >

github_iconTop Results From Across the Web

Copying objects - Amazon Simple Storage Service
Create a copy of an object that is already stored in Amazon S3 with the copy operation. ... Rename objects by copying them...
Read more >
boto3 copy vs copy_object regarding file permission ACL in s3
This is not the exact answer that I want but it seems to work for now. I am not sure how to maintain...
Read more >
S3 — Boto3 Docs 1.26.34 documentation - AWS
If the bucket is owned by a different account, the request fails with the HTTP ... S3 receives the copy request or while...
Read more >
How to Copy or Move Objects from one S3 bucket to another ...
Using the AWS S3 CLI Tool. So here are the ingredients for this recipe again as discussed in part 1: 2 - S3...
Read more >
Copy objects between Amazon S3 buckets - AWS re:Post
I want to copy or move all my objects from one Amazon Simple Storage Service (Amazon S3) bucket to another bucket. How can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found