Python code to copy all objects from one S3 bucket to another

github logo ・1 min read

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)
twitter logo DISCUSS
Classic DEV Post from May 10

Why I ignore the hype (and you should too)

It’s been 20 years since I made my first website. I've been burned by the hype ti...

scott hutchinson profile image

Tip: You can configure your reading experience, such as using sans serif fonts.

Go to your the "misc." section of your settings.