how to copy s3 object from one bucket to another using python s3fs

203 views Asked by At

Using python s3fs, how do you copy an object from one s3 bucket to another? I have found answers using boto3, but could not find anything when looking through the s3fs docs.

1

There are 1 answers

0
C.Nivs On

Open from one bucket and write to another:

s3 = S3FileSystem(...)

# You'll want to set a block size
# if your files are particularly large
block_size = 2**20

with s3.open('bucket_a/file', 'rb', block_size=block_size) as infile, s3.open('bucket_b/file', 'wb') as outfile:
    for line in infile:
        outfile.write(line)