Option 1 – Using AWS CLI

Step 1

1
export bucketname='your-bucket-here'

Step 2

1
aws s3api delete-objects --bucket $bucketname --delete "$(aws s3api list-object-versions --bucket $bucketname --output=json --query='{Objects: *[].{Key:Key,VersionId:VersionId}}')";

Step 3

1
aws s3 rb s3://$bucketname

Option 2 – Using Python

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#!/usr/bin/env python

BUCKET = 'your-bucket-here'

import boto3

s3 = boto3.resource('s3')
bucket = s3.Bucket(BUCKET)
bucket.object_versions.delete()

bucket.delete()