简体   繁体   中英

Using boto3, while copying from whole folder or file from one s3 bucket to another in same region, how to provide access key and secret access key?

I want to copy a file from one s3 bucket to another in same region. Both buckets have different access key and secret key. How do I provide these secret and access key using the following python code snippet:

import boto3
s3 = boto3.resource('s3')
copy_source = {
               'Bucket': 'mybucket',
               'Key': 'mykey'
              }
bucket = s3.Bucket('otherbucket')
bucket.copy(copy_source, 'otherkey')

You don't. Copying objects, whether from one bucket to another or within the same bucket, requires you to use one set of credentials that has the necessary permissions in both buckets.

When you perform a copy object, the request is actually sent by your client to the destination bucket, which sends the request for the content to the source bucket using a path that is internal to S3, but using the same credentials you used for the first request. The object is transferred without you needing to download it and then upload it again.

If you don't have a single set of credentials that can access both buckets, you have to resort to downloading and re-uploading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM