0

I've been trying to transfer the objects from one bucket of an account1 to another bucket of an account2.

I'm trying to:

source_bucket = s3.Bucket('source-bucket')
destination_bucket = s3.Bucket('destination-bucket')
destination_keys = [object.key for object in destination_bucket.objects.all()]
for object in source_bucket.objects.all():
  if (object.key not in destination_keys):
    # copy object.key to destination

How can I make the copy?

  • Hi :) Does this answer your question? https://www.stackvidhya.com/copy-move-files-between-buckets-using-boto3/ – Shimon Cohen Mar 22 '22 at 19:29
  • Or this, from this website: https://stackoverflow.com/questions/47468148/how-to-copy-s3-object-from-one-bucket-to-another-using-python-boto3 – Shimon Cohen Mar 22 '22 at 19:32
  • Are you running this code using credentials from the 'source' or 'destination' AWS account? Are you successfully able to list objects in both buckets? If so, then it is likely that your permissions are setup correctly. It would just be a matter of creating the object. You can do this with the [`copy()`](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Object.copy) method. – John Rotenstein Mar 23 '22 at 01:24

0 Answers0