I got frustrated having to empty and delete S3 buckets using the AWS Console, so I created a Python
script to do it for me!
WARNING: This method bypasses all of the usual safety associated with deleting buckets with the AWS Console
, so make absolutely sure you want to delete your bucket before running this script.
# Use the boto3 library to communicate with AWS import boto3 # Buckets you want to delete, specified by their names BUCKETS = [ "bucket-one", "bucket-two", ] s3 = boto3.resource("s3") for bucket_name in BUCKETS: # For each bucket, create a resource object with boto3 bucket = s3.Bucket(bucket_name) # Delete all of the objects in the bucket bucket.object_versions.delete() # Delete the bucket itself! bucket.delete()
Top comments (0)