Skip to content

Instantly share code, notes, and snippets.

@rosenhouse
Last active December 12, 2018 19:27
Show Gist options
  • Save rosenhouse/8126048 to your computer and use it in GitHub Desktop.
Save rosenhouse/8126048 to your computer and use it in GitHub Desktop.
Recursive delete on S3
import boto
def delete_recursive(bucketname, keyprefix):
'''
Recusively delete all keys with given prefix from the named bucket
Stolen from http://stackoverflow.com/a/10055320/141084
'''
s3 = boto.connect_s3()
bucket = s3.get_bucket(bucketname, validate=False)
bucketListResultSet = bucket.list(prefix=keyprefix)
return bucket.delete_keys([key.name for key in bucketListResultSet])
@y2k-shubham
Copy link

This appears to be a more robust extension of above approach, incorporating pagination requirements of boto3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment