Created
February 4, 2021 11:27
-
-
Save ivankeller/fcfbf11b9fb4264bd0afd8d73405cbec to your computer and use it in GitHub Desktop.
delete versioned AWS s3 buckets with boto3
This file contains 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 | |
# for listing and selecting the buckets you want to delete use list_s3_buckets.py gist | |
import boto3 | |
# list of the bucket names you want to delete | |
BUCKETS_TO_DELETE = [] | |
def delete_versioned_bucket(s3resource, bucket_name): | |
print(f'started deleting bucket {bucket_name}') | |
bucket = s3resource.Bucket(bucket_name) | |
bucket.object_versions.delete() | |
bucket.delete() | |
print(f'deleted bucket {bucket_name}') | |
s3resource = boto3.resource('s3') | |
# delete the buckets | |
for bucket_name in BUCKETS_TO_DELETE: | |
delete_versioned_bucket(s3resource, bucket_name) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment