Home > Software engineering >  How can I move a sub-folder to another main folder within same s3 bucket boto3?
How can I move a sub-folder to another main folder within same s3 bucket boto3?

Time:11-12

dst= s3.get_object(Bucket='bucket_name', )   

copy_source = {
    'Bucket': 'bucket_name',
    'Key': 'folder_path'
}   

dst.copy(copy_source,'Key': 'target_folder_path')

CodePudding user response:

You will need to:

  • Loop through a list of the objects to 'move' (you can specify a prefix with s3_resource.Bucket('bucket-name').objects.filter(Prefix='path/'))
  • For each object you wish to 'move':
  • Use copy() to copy the object to the desired path
  • Then delete() the source object
  • Related