-
Notifications
You must be signed in to change notification settings - Fork 16
/
run_terminate_s3_bucket.py
executable file
·51 lines (36 loc) · 1.72 KB
/
run_terminate_s3_bucket.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
from run_common import AWSCli
from run_common import print_message
from run_common import print_session
def run_terminate_s3_bucket(name, settings):
aws_cli = AWSCli()
bucket_name = settings['BUCKET_NAME']
################################################################################
print_session('terminate %s' % name)
################################################################################
print_message('delete life cycle')
cmd = ['s3api', 'delete-bucket-lifecycle', '--bucket', bucket_name]
aws_cli.run(cmd, ignore_error=True)
################################################################################
print_message('delete web hosting')
cmd = ['s3api', 'delete-bucket-website', '--bucket', bucket_name]
aws_cli.run(cmd, ignore_error=True)
################################################################################
print_message('delete policy')
cmd = ['s3api', 'delete-bucket-policy', '--bucket', bucket_name]
aws_cli.run(cmd, ignore_error=True)
################################################################################
print_message('delete cors')
cmd = ['s3api', 'delete-bucket-cors', '--bucket', bucket_name]
aws_cli.run(cmd, ignore_error=True)
################################################################################
print_message('restore public access block')
pp = {
"BlockPublicAcls": True,
"IgnorePublicAcls": True,
"BlockPublicPolicy": True,
"RestrictPublicBuckets": True
}
cmd = ['s3api', 'put-public-access-block', '--bucket', bucket_name]
cmd += ['--public-access-block-configuration', json.dumps(pp)]
aws_cli.run(cmd, ignore_error=True)