SHARE
TWEET

Untitled

a guest May 24th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. import boto3
  3.  
  4.  
  5. def delete_all_version_fuzzy(bucket_name, prefix, do_it=False):
  6.     s3 = boto3.resource('s3')
  7.     bucket = s3.Bucket(bucket_name)
  8.  
  9.     count = 0
  10.     print("Searching bucket({}) for prefix({})".format(bucket.name, prefix))
  11.     for version in bucket.object_versions.filter(Prefix=prefix):
  12.         count += 1
  13.         if do_it:
  14.             version.delete()
  15.  
  16.     print("Deleted {} versions {}".format(count, "were deleted" if do_it else "would be deleted"))
  17.  
  18.  
  19. if __name__ == '__main__':
  20.     if len(sys.argv) not in (3, 4):
  21.         print("usage: delete_them_all.py bucket prefix [-y]")
  22.         exit(1)
  23.     delete_all_version_fuzzy(sys.argv[1], sys.argv[2], len(sys.argv) == 4 and sys.argv[3] == '-y')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top