Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anuragmathur1/31f08410ff4ffd4de34fc37da0ca25f8 to your computer and use it in GitHub Desktop.
Save anuragmathur1/31f08410ff4ffd4de34fc37da0ca25f8 to your computer and use it in GitHub Desktop.
You can not use cli to delete all versions of an object in a bucket. That will prevent you from removing the bucket as well. The below 4 lines will delete all versions of all all objects in the given s3 bucket.
#!/usr/bin/env python
import boto3
s3 = boto3.resource('s3')
bucket = s3.Bucket('<<Bucket-name-here>>')
bucket.object_versions.all().delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment