Created
July 20, 2018 16:21
-
-
Save alicefuzier/934e847ccda4b635754aada49a07a54a to your computer and use it in GitHub Desktop.
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
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