Вы можете попробовать ниже:
import boto
c = boto.connect_s3()
src = c.get_bucket('source_bucket')
dst = c.get_bucket('destination_bucket')
for k in src.list():
# copy files to your destination bucket
dst.copy_key(k.key.name, src.name, k.key.name)
# then delete the source key
k.delete()
Другой метод, который я сделал, как показано ниже:
def get_object(s3, bucketName, file):
try:
s3_file = s3.get_object(
Bucket = bucketName,
Key = file
)
return s3_file
except Exception as e:
logger.info('file not found')
#Decription: This method enables to put file long with its conetent from one location to another
def move_objects(s3, bucketName, file, newFolder):
#s3_object = s3.get_object(Bucket=bucketName, Key=file)
#serializedObject = file['Body'].read().decode('utf-8')
response = s3.put_object(
Bucket = bucketName,
Key = newFolder,
Body = file.read().decode('utf-8')
)
#Decription: This method enables to delete file from its original location
def delete_objects(s3, bucketName, file):
response = s3.delete_object(
Bucket = bucketName,
Key = file
)
Также см. Это видео: https://youtu.be/7gqvV4tUxmY