-
Notifications
You must be signed in to change notification settings - Fork 16
/
run_terminate_s3_vue.py
executable file
·61 lines (44 loc) · 2.23 KB
/
run_terminate_s3_vue.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
52
53
54
55
56
57
58
59
60
61
import json
from run_common import AWSCli
from run_common import print_message
def run_terminate_s3_vue(name, settings):
aws_cli = AWSCli()
deploy_bucket_name = settings['BUCKET_NAME']
################################################################################
print_message('terminate %s' % name)
################################################################################
print_message('cleanup deploy bucket')
cmd = ['s3', 'rm', 's3://%s' % deploy_bucket_name, '--recursive']
delete_result = aws_cli.run(cmd, ignore_error=True)
for ll in delete_result.split('\n'):
print(ll)
################################################################################
print_message('remove tag from deploy bucket')
cmd = ['s3api', 'delete-bucket-tagging', '--bucket', deploy_bucket_name]
aws_cli.run(cmd, ignore_error=True)
################################################################################
print_message('delete web hosting')
cmd = ['s3api', 'delete-bucket-website', '--bucket', deploy_bucket_name]
aws_cli.run(cmd, ignore_error=True)
################################################################################
print_message('delete policy')
cmd = ['s3api', 'delete-bucket-policy', '--bucket', deploy_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', deploy_bucket_name]
cmd += ['--public-access-block-configuration', json.dumps(pp)]
aws_cli.run(cmd, ignore_error=True)
################################################################################
print_message('invalidate cache from cloudfront')
cf_dist_id = settings.get('CLOUDFRONT_DIST_ID', '')
if len(cf_dist_id) > 0:
cmd = ['cloudfront', 'create-invalidation', '--distribution-id', cf_dist_id, '--paths', '/*']
invalidate_result = aws_cli.run(cmd, ignore_error=True)
print(invalidate_result)