Skip to content

Instantly share code, notes, and snippets.

@alicefuzier
Created July 20, 2018 16:21
Show Gist options
  • Save alicefuzier/934e847ccda4b635754aada49a07a54a to your computer and use it in GitHub Desktop.
Save alicefuzier/934e847ccda4b635754aada49a07a54a to your computer and use it in GitHub Desktop.
import boto3
from tenacity import retry
client = boto3.client('s3')
paginator = client.get_paginator('list_objects_v2')
@retry
def delete_objects(client, objects):
response = client.delete_objects(Bucket='wellcomecollection-tmp-wiretap',Delete=objects)
errors = response.get('Errors')
deleted = response.get('Deleted')
if errors:
raise Exception(f'There are errors in the delete response: {errors}')
#print(f'Deleted {len(deleted)} objects')
for page in paginator.paginate(Bucket='wellcomecollection-tmp-wiretap'):
if "Contents" not in page:
break
keys = [{'Key': content['Key']} for content in page['Contents']]
objects = {
'Objects': keys
}
delete_objects(client,objects)
print("Done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment