Created
January 24, 2019 17:02
-
-
Save cphrmky/171ddbaa6d4e3f65a18ebe1e436917ba to your computer and use it in GitHub Desktop.
Use boto3 to remove all object versions from an S3 bucket so it can be deleted.
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
BUCKET = 'your-bucket-here' # protocol prefix like s3://your-bucket-here is not required | |
import boto3 | |
s3 = boto3.resource('s3') | |
bucket = s3.Bucket(BUCKET) | |
bucket.object_versions.delete() | |
# if you want to delete the now-empty bucket as well, uncomment this line: | |
#bucket.delete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment