Skip to content

Instantly share code, notes, and snippets.

@clarkritchie
Created May 17, 2024 03:08
Show Gist options
  • Save clarkritchie/da5c98c1be0df95850fb17377204077a to your computer and use it in GitHub Desktop.
Save clarkritchie/da5c98c1be0df95850fb17377204077a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
#
# Quick and dirty script to purge contents from a versioned S3 bucket
#
import boto3, sys
BUCKET = 'some-bucket'
if len(sys.argv) > 1:
path = sys.argv[1]
else:
path = '/'
s3 = boto3.resource('s3')
bucket = s3.Bucket(BUCKET)
bucket.object_versions.filter(Prefix=path).delete()
# bucket.delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment