import boto3
s3_resource = boto3.resource('s3')
new_bucket_name = "targetBucketName"
bucket_to_copy = "sourceBucketName"
for key in s3.list_objects(Bucket=bucket_to_copy)['Contents']:
files = key['Key']
copy_source = {'Bucket': "bucket_to_copy",'Key': files}
s3_resource.meta.client.copy(copy_source, new_bucket_name, files)
print(files)
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (5)
Its missing:
s3 = boto3.client('s3')
under import boto3
I've copied above code and getting error for "s3.list_objects" in for loop, below error :
NameError: name 's3' is not defined
Probably the author forget to change:
E.g.:
Thanks for the code, it helped me
Some comments may only be visible to logged-in visitors. Sign in to view all comments.