Amazon S3 boto - how to delete folder?

wade huang picture wade huang · Jul 11, 2012 · Viewed 57.6k times · Source

I created a folder in s3 named "test" and I pushed "test_1.jpg", "test_2.jpg" into "test".

How can I use boto to delete folder "test"?

Answer

Raz picture Raz · Dec 18, 2018

Here is 2018 (almost 2019) version:

s3 = boto3.resource('s3')
bucket = s3.Bucket('mybucket')
bucket.objects.filter(Prefix="myprefix/").delete()