Skip to content

Instantly share code, notes, and snippets.

@aphexlog
Created July 16, 2023 21:23
Show Gist options
  • Select an option

  • Save aphexlog/d5b552ca714d2e677645441ae8abd6bf to your computer and use it in GitHub Desktop.

Select an option

Save aphexlog/d5b552ca714d2e677645441ae8abd6bf to your computer and use it in GitHub Desktop.
Deletes all objects in an s3 bucket
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