Skip to content

Instantly share code, notes, and snippets.

@cphrmky
Created January 24, 2019 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cphrmky/171ddbaa6d4e3f65a18ebe1e436917ba to your computer and use it in GitHub Desktop.
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.
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