Last active
September 23, 2022 02:28
-
-
Save pwmcintyre/0259f9673a20a4b23cf2845d85f40026 to your computer and use it in GitHub Desktop.
purge an s3 bucket of all it's contents, including all object versions
This file contains hidden or 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
#!/usr/bin/env python | |
# $ nohup python3 ./purge.py foo-bucket & | |
import sys | |
import boto3 | |
# Take the bucket name from command line args | |
BUCKET = sys.argv[1] | |
s3 = boto3.resource('s3') | |
bucket = s3.Bucket(BUCKET) | |
# Delete all object versions in the bucket | |
bucket.object_versions.delete() |
This file contains hidden or 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
# This is useful for long-running scripts, as your IAM Token will expire, or something else will break | |
# $ nohup bash z_keepalive.sh & | |
while true | |
do | |
python3 ./purge.py foo-bucket | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment