Created
July 16, 2023 21:23
-
-
Save aphexlog/d5b552ca714d2e677645441ae8abd6bf to your computer and use it in GitHub Desktop.
Deletes all objects in an s3 bucket
This file contains hidden or 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
| import boto3 | |
| def delete_all_objects(bucket_name): | |
| s3 = boto3.resource('s3') | |
| bucket = s3.Bucket(bucket_name) | |
| bucket.objects.all().delete() | |
| if __name__ == "__main__": | |
| import sys | |
| bucket_name = sys.argv[1] # pass the bucket name as an argument to the script | |
| delete_all_objects(bucket_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment