Last active
February 11, 2021 00:12
-
-
Save ryangraham/74700d75f7811fdb56374cfaf82e0806 to your computer and use it in GitHub Desktop.
Purge all object versions from a bucket so terraform can destroy it
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
| #!/usr/bin/env python3 | |
| import argparse | |
| import boto3 | |
| def main(bucket_name): | |
| session = boto3.Session() | |
| s3 = session.resource(service_name='s3') | |
| bucket = s3.Bucket(bucket_name) | |
| bucket.object_versions.delete() | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('bucket_name') | |
| args = parser.parse_args() | |
| main(args.bucket_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment