I'm able to delete individual files within a "Folder" on Amazon S3 using the following:
s3 = AWS::S3.new(:access_key_id => ENV['AWS_ACCESS_KEY_ID'], :secret_access_key => ENV['AWS_ACCESS_KEY'])
folder_path = 'uploads/'[email protected]_filename
s3.buckets[ENV['AWS_BUCKET']].objects.with_prefix(folder_path).delete_all
but this leaves an empty folder. How can I just delete the folder entirely (folder_path)?
To delete folders from an S3 bucketIn the Buckets list, choose the name of the bucket that you want to delete folders from. In the Objects list, select the check box next to the folders and objects that you want to delete. Choose Delete.
To delete the object, select the object, and choose delete and confirm your choice by typing delete in the text field. On, Amazon S3 will permanently delete the object version. Select the object version that you want to delete, and choose delete and confirm your choice by typing permanently delete in the text field.
The subfolders DO get deleted when the retention policy set to: "This rule applies to all objects in the bucket".
Navigate to the Amazon S3 bucket or folder that contains the objects that you want to delete. Select the check box to the left of the names of the objects that you want to delete. Choose Actions and choose Delete from the list of options that appears. Alternatively, choose Delete from the options in the upper right.
This is an old question, but you can do this for aws-sdk 2.0>
s3 = Aws::S3::Resource.new
folder = 'path/to/the/folder'
objects = s3.bucket(ENV['S3_BUCKET_NAME']).objects({prefix: folder})
objects.batch_delete!
delete
was depreciated
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With