Created
April 9, 2020 02:43
-
-
Save hernandesbsousa/8ef912f87cb43b1b8050949fe8c42b37 to your computer and use it in GitHub Desktop.
cleanup s3 bucket (even old versions)
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 | |
session = boto3.Session() | |
s3 = session.resource(service_name='s3') | |
bucket = s3.Bucket('bucket-name') | |
objects = bucket.object_versions.filter( | |
Prefix='prefix/' | |
).all() | |
count = 1 | |
for object in objects: | |
print("Deleting {}, total {}".format(object.object_key, count)) | |
object.delete() | |
count += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment