-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbucketFile.py
More file actions
38 lines (32 loc) · 896 Bytes
/
bucketFile.py
File metadata and controls
38 lines (32 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
import sys
import boto3
import run_newwebserver
s3 = boto3.resource("s3")
# #Lists buckets and its contents
def list_buckets_and_contents():
try:
for bucket_name in s3.buckets.all():
print (bucket_name)
print("-------------------------------------------------")
for item in bucket_name.objects.all():
print("\t%s" % item.key)
except Exception:
print('No Buckets Found!')
# #Delete entire bucket
def delete_bucket():
for bucket_name in s3.buckets.all():
try:
response = bucket_name.delete()
print (response)
except Exception as error:
print (error)
# #delete contents in bucket
def delete_contents():
for bucket_name in s3.buckets.all():
for key in bucket_name.objects.all():
try:
response = key.delete()
print (response)
except Exception as error:
print (error)