-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclear.sh
115 lines (97 loc) · 2.43 KB
/
clear.sh
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
clean_up_kms_resources() {
while [[ $# -gt 0 ]]; do
case $1 in
--endpoint)
endpoint="$2"
shift 2
;;
--region)
region="$2"
shift 2
;;
*)
echo "Unknown parameter passed to clean_up_resources: $1\n"
exit 1
;;
esac
done
# 모든 KMS 키 삭제
echo "Listing all KMS keys..."
local key_ids
key_ids=$(aws kms list-keys \
--endpoint-url "$endpoint" \
--region "$region" \
--query "Keys[*].KeyId" \
--output text)
for key_id in $key_ids; do
echo "Deleting KMS key: $key_id"
# 키 삭제를 위해 비활성화
aws kms schedule-key-deletion \
--endpoint-url "$endpoint" \
--region "$region" \
--key-id "$key_id" \
--pending-window-in-days 7
if [ $? -eq 0 ]; then
echo "Scheduled deletion for KMS key: $key_id\n"
else
echo "Failed to schedule deletion for KMS key: $key_id\n"
fi
done
echo "Cleanup KMS keys completed.\n"
}
clean_up_dynamo_db_resources() {
while [[ $# -gt 0 ]]; do
case $1 in
--endpoint)
endpoint="$2"
shift 2
;;
--region)
region="$2"
shift 2
;;
*)
echo "Unknown parameter passed to clean_up_resources: $1\n"
exit 1
;;
esac
done
# 모든 DynamoDB 테이블 삭제
echo "Listing all DynamoDB tables..."
local table_names
table_names=$(aws dynamodb list-tables \
--endpoint-url "$endpoint" \
--region "$region" \
--query "TableNames" \
--output text)
for table_name in $table_names; do
echo "Deleting DynamoDB table: $table_name"
aws dynamodb delete-table \
--endpoint-url "$endpoint" \
--region "$region" \
--table-name "$table_name"
if [ $? -eq 0 ]; then
echo "Successfully deleted DynamoDB table: $table_name"
else
echo "Failed to delete DynamoDB table: $table_name"
fi
done
echo "Cleanup DynamoDB tables completed.\n"
}
# 메인 함수
main() {
local aws_dynamodb_endpoint="http://localhost:4566"
local aws_kms_endpoint="http://localhost:4574"
local aws_region="ap-northeast-2"
echo "Starting cleanup process...\n"
clean_up_kms_resources \
--endpoint "$aws_kms_endpoint" \
--region "$aws_region"
clean_up_dynamo_db_resources \
--endpoint "$aws_dynamodb_endpoint" \
--region "$aws_region"
echo "Cleanup process completed."
}
# 스크립트 실행
main