Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #87 create cleanup script for all s3 buckets #109

Open
wants to merge 9 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions devops/DeleteAllS3BucketsIssue116.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#s3BucketDelete.py for issue 87 Create a cleanup script for all s3 buckets 1jc
#revision for issue 116 Sprint 4 Fix issue #87 Fix script to delete all s3 buckets even with data 1jc

import boto3
client = boto3.client('s3')
response = client.list_buckets()
for name in response ['Buckets']:
print (name['Name'])

response = client.delete_buckets()
print(response)
29 changes: 29 additions & 0 deletions devops/s3BucketDelete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#s3BucketDelete.py for issue 87 Create a cleanup script for all s3 buckets 1jc

import boto3
client = boto3.client('s3')

#need name of bucket for delete

bucket_name = str (input ('Please provide bucket name to be deleted: '))
print ('Before deleting the bucket we need to check if its empty. Checking...')

#need to check if bucket is empty

objs = client.list_objects_v2 (Bucket = bucket_name)
filecount = objs ['KeyCount']
print (filecount)
filecount = objs ['KeyCount']

#need to make sure filecount is zero

if filecount == 0:
response = client.delete_bucket(
Bucket = bucket_name)
print ('{} has been deleted successfully!!!'.format (bucket_name))

#will not delete s3 bucket if filecount > zero must be empty

else:
print ('{} is not empty!!!'.format (bucket_name))
print ('Please make sure s3 bucket is empty before deleting!!!')
7 changes: 7 additions & 0 deletions devops/s3BucketList.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#s3BucketList.py for issue 87 Create a cleanup script for all listing of s3 buckets 1jc

import boto3
client = boto3.client('s3')
response = client.list_buckets()
for name in response ['Buckets']:
print (name['Name'])