Last active
December 12, 2018 19:27
-
-
Save rosenhouse/8126048 to your computer and use it in GitHub Desktop.
Recursive delete on S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This appears to be a more robust extension of above approach, incorporating
pagination
requirements ofboto3