1 Answer
- Newest
- Most votes
- Most comments
0
Hello.
In the case of boto3, I don't think it is possible to copy all at once.
I think it would be better to create a Python script that retrieves the copy source objects all at once using s3.list_objects_v2() and executes copy_object() for each object.
For example, the code below behaves like copying objects one by one.
import boto3
next_token = ''
source_prefix = 'source-folder/'
target_prefix = 'target-folder/'
s3 = boto3.client('s3')
while True:
if next_token == '':
response = s3.list_objects_v2(Bucket="S3-Source-Bucket-Name", Prefix=source_prefix)
else:
response = s3.list_objects_v2(Bucket="S3-Source-Bucket-Name", Prefix=source_prefix, ContinuationToken=next_token)
if 'Contents' in response:
contents = response['Contents']
for content in contents:
s3.copy_object(Bucket="S3-Target-Bucket-Name", Key=target_prefix, CopySource={'Bucket': "S3-Source-Bucket-Name", 'Key': content['Key']})
if 'NextContinuationToken' in response:
next_token = response['NextContinuationToken']
else:
break
Relevant content
- Accepted Answerasked 4 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago