-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteardown.sh
More file actions
executable file
·178 lines (145 loc) · 3.96 KB
/
teardown.sh
File metadata and controls
executable file
·178 lines (145 loc) · 3.96 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
set -e
# Master teardown script for Semantic Cache Demo
# Deletes all stacks in reverse order
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
AWS_PROFILE="${AWS_PROFILE:-semantic-cache-demo}"
DEFAULT_AWS_REGION="us-east-2"
# Flags
FORCE=false
print_header() {
echo -e "${RED}==========================================${NC}"
echo -e "${RED}$1${NC}"
echo -e "${RED}==========================================${NC}"
echo ""
}
print_step() {
local step=$1
local message=$2
echo -e "${YELLOW}[$step]${NC} $message"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_error() {
echo -e "${RED}Error: $1${NC}"
}
print_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --force, -f Skip confirmation prompt"
echo " -h, --help Show this help message"
echo ""
}
get_aws_region() {
local profile_region=$(aws configure get region --profile $AWS_PROFILE 2>/dev/null || echo "")
if [ -n "$profile_region" ]; then
echo "$profile_region"
else
echo "$DEFAULT_AWS_REGION"
fi
}
delete_stack() {
local stack_name=$1
# Check if stack exists
if ! aws cloudformation describe-stacks --stack-name "$stack_name" \
--region "$AWS_REGION" --profile "$AWS_PROFILE" >/dev/null 2>&1; then
echo -e " ${BLUE}→${NC} $stack_name (does not exist, skipping)"
return
fi
echo -e " ${BLUE}→${NC} Deleting $stack_name..."
aws cloudformation delete-stack \
--stack-name "$stack_name" \
--region "$AWS_REGION" \
--profile "$AWS_PROFILE"
aws cloudformation wait stack-delete-complete \
--stack-name "$stack_name" \
--region "$AWS_REGION" \
--profile "$AWS_PROFILE" 2>/dev/null || true
print_success "$stack_name deleted"
}
confirm_teardown() {
if [ "$FORCE" = true ]; then
return
fi
echo -e "${RED}WARNING: This will delete ALL infrastructure for the Semantic Cache Demo!${NC}"
echo ""
echo "The following stacks will be deleted:"
echo " - semantic-cache-demo-ramp-simulator"
echo " - semantic-cache-demo-cache-management"
echo " - semantic-cache-demo-dashboard"
echo " - semantic-cache-demo-agentcore-deploy"
echo " - semantic-cache-demo-agentcore"
echo " - semantic-cache-vpc-endpoints"
echo " - semantic-cache-demo-infrastructure (ElastiCache)"
echo ""
read -p "Are you sure you want to continue? (yes/no): " confirm
if [ "$confirm" != "yes" ]; then
echo "Teardown cancelled."
exit 0
fi
echo ""
}
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
--force|-f)
FORCE=true
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
print_error "Unknown option: $1"
print_usage
exit 1
;;
esac
done
}
main() {
parse_args "$@"
AWS_REGION=$(get_aws_region)
print_header "Semantic Cache Demo - Full Teardown"
echo "Region: $AWS_REGION"
echo "Profile: $AWS_PROFILE"
echo ""
confirm_teardown
print_step "1/7" "Ramp-up Simulator Lambda"
delete_stack "semantic-cache-demo-ramp-simulator"
echo ""
print_step "2/7" "Cache Management Lambda"
delete_stack "semantic-cache-demo-cache-management"
echo ""
print_step "3/7" "CloudWatch Dashboard"
delete_stack "semantic-cache-demo-dashboard"
echo ""
print_step "4/7" "AgentCore CodeBuild Deployment"
delete_stack "semantic-cache-demo-agentcore-deploy"
echo ""
print_step "5/7" "AgentCore IAM Roles"
delete_stack "semantic-cache-demo-agentcore"
echo ""
print_step "6/7" "VPC Endpoints"
delete_stack "semantic-cache-vpc-endpoints"
echo ""
print_step "7/7" "ElastiCache Infrastructure"
delete_stack "semantic-cache-demo-infrastructure"
echo ""
print_header "Teardown Complete!"
echo "All stacks have been deleted."
echo ""
echo -e "${YELLOW}Note:${NC} AgentCore runtime may need manual cleanup:"
echo " agentcore destroy --agent semantic_cache_demo --force"
echo ""
}
main "$@"