Skip to content

Commit

Permalink
add script to empty s3 bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
FaithKovi committed Jul 30, 2024
1 parent 08d6ade commit 5e0c4f7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions terraform/empty_bucket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import boto3
import os

def get_bucket_name(tfvars_file):
with open(tfvars_file, 'r') as file:
for line in file:
if line.startswith("bucket_name"):
return line.split('=')[1].strip().replace('"', '')

def empty_bucket(bucket_name):
s3 = boto3.resource('s3')
bucket = s3.Bucket(bucket_name)
bucket.objects.all().delete()

if __name__ == "__main__":
tfvars_file = 'variables.tfvars'
bucket_name = get_bucket_name(tfvars_file)
print(f"Emptying bucket: {bucket_name}")
empty_bucket(bucket_name)
print("Bucket emptied successfully.")

0 comments on commit 5e0c4f7

Please sign in to comment.