Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a folder in s3?

Tags:

ruby

amazon-s3

I have the following hierarchy in my s3 bucket

bucket_name/folder1/folder2/file1
bucket_name/folder1/folder2/file1

I am able to delete all the files within folder2, but that leaves the bucket with empty folders as folder1/folder2.

What is the appropriate way of deleting those folders?

Here is what I do to delete a particular file:

Where s3 is my Amazon s3 instance:

s3.buckets[my_bucket_name].objects[path].delete

Ideally I would like to delete the folders an all the contents.

like image 675
Hommer Smith Avatar asked Oct 31 '22 18:10

Hommer Smith


1 Answers

You can use aws-cli to delete a folder :

aws s3 rm s3://mybucket/ --recursive

In order to check what the delete operation will delete, you can set 'dryrun' flag :

aws s3 rm s3://mybucket/ --recursive --dryrun

like image 194
Parul Singh Avatar answered Nov 15 '22 05:11

Parul Singh