-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdeploy-all.sh
More file actions
253 lines (226 loc) · 12.2 KB
/
deploy-all.sh
File metadata and controls
253 lines (226 loc) · 12.2 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/bin/bash
# Deploy Nova Sonic Bidi Voice Agent - Complete Deployment Script
echo -e "\033[0;36m=== Nova Sonic Bidi Voice Agent Deployment ===\033[0m"
# Step 1: Verify AWS credentials
echo -e "\n\033[0;33m[1/11] Verifying AWS credentials...\033[0m"
echo -e "\033[0;90m (Checking AWS CLI configuration and validating access)\033[0m"
# Check if AWS credentials are configured
CALLER_IDENTITY=$(aws sts get-caller-identity 2>&1)
if [ $? -ne 0 ]; then
echo -e "\033[0;31mAWS credentials are not configured or have expired\033[0m"
echo -e "\n\033[0;33mPlease configure AWS credentials using one of these methods:\033[0m"
echo -e "\033[0;36m 1. Run: aws configure\033[0m"
echo -e "\033[0;36m 2. Set environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY\033[0m"
echo -e "\033[0;36m 3. Use AWS SSO: aws sso login --profile <profile-name>\033[0m"
echo -e "\n\033[0;90mFor more info: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html\033[0m"
exit 1
fi
# Display current AWS identity
ACCOUNT_ID=$(echo "$CALLER_IDENTITY" | jq -r '.Account')
ARN=$(echo "$CALLER_IDENTITY" | jq -r '.Arn')
echo -e "\033[0;32m Authenticated as: $ARN\033[0m"
echo -e "\033[0;32m AWS Account: $ACCOUNT_ID\033[0m"
# Step 2: Check AWS CLI version
echo -e "\n\033[0;33m[2/11] Checking AWS CLI version...\033[0m"
AWS_VERSION=$(aws --version 2>&1)
if [[ $AWS_VERSION =~ aws-cli/([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
echo -e "\033[0;90m Current version: aws-cli/$MAJOR.$MINOR.$PATCH\033[0m"
# Check if version is >= 2.31.13
if [ "$MAJOR" -gt 2 ] || \
[ "$MAJOR" -eq 2 -a "$MINOR" -gt 31 ] || \
[ "$MAJOR" -eq 2 -a "$MINOR" -eq 31 -a "$PATCH" -ge 13 ]; then
echo -e "\033[0;32m ✓ AWS CLI version is compatible\033[0m"
else
echo -e "\033[0;31m ❌ AWS CLI version 2.31.13 or later is required\033[0m"
echo ""
echo -e "\033[0;33m AgentCore support was added in AWS CLI v2.31.13 (January 2025)\033[0m"
echo -e "\033[0;33m Your current version: aws-cli/$MAJOR.$MINOR.$PATCH\033[0m"
echo ""
echo -e "\033[0;33m Please upgrade your AWS CLI:\033[0m"
echo -e "\033[0;36m https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html\033[0m"
exit 1
fi
else
echo -e "\033[0;33m ⚠ Could not parse AWS CLI version, continuing anyway...\033[0m"
fi
# Step 3: Check AgentCore availability in current region
echo -e "\n\033[0;33m[3/11] Checking AgentCore availability in current region...\033[0m"
CURRENT_REGION=$(aws configure get region)
if [ -z "$CURRENT_REGION" ]; then
echo -e "\033[0;31m ❌ No AWS region configured\033[0m"
echo ""
echo -e "\033[0;33m Please configure your AWS region using:\033[0m"
echo -e "\033[0;36m aws configure set region <your-region>\033[0m"
echo ""
echo -e "\033[0;90m For supported regions, see:\033[0m"
echo -e "\033[0;90m https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-regions.html\033[0m"
exit 1
fi
echo -e "\033[0;90m Target region: $CURRENT_REGION\033[0m"
# Try to list AgentCore runtimes to verify service availability
AGENTCORE_CHECK=$(aws bedrock-agentcore-control list-agent-runtimes --region "$CURRENT_REGION" --max-results 1 2>&1)
if [ $? -ne 0 ]; then
echo -e "\033[0;31m ❌ AgentCore is not available in region: $CURRENT_REGION\033[0m"
echo ""
echo -e "\033[0;90m Error details:\033[0m"
echo -e "\033[0;90m $AGENTCORE_CHECK\033[0m"
echo ""
echo -e "\033[0;90m For supported regions, see:\033[0m"
echo -e "\033[0;90m https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-regions.html\033[0m"
exit 1
fi
echo -e "\033[0;32m ✓ AgentCore is available in $CURRENT_REGION\033[0m"
# Step 4: Update Dockerfile with current region
echo -e "\n\033[0;33m[4/11] Updating Dockerfile with current region...\033[0m"
echo -e "\033[0;90m (Setting AWS_REGION and AWS_DEFAULT_REGION to $CURRENT_REGION in agent/Dockerfile)\033[0m"
DOCKERFILE_PATH="agent/Dockerfile"
if [ -f "$DOCKERFILE_PATH" ]; then
sed -i.bak "s/AWS_REGION=[a-z0-9-]*/AWS_REGION=$CURRENT_REGION/g" "$DOCKERFILE_PATH"
sed -i.bak "s/AWS_DEFAULT_REGION=[a-z0-9-]*/AWS_DEFAULT_REGION=$CURRENT_REGION/g" "$DOCKERFILE_PATH"
rm -f "${DOCKERFILE_PATH}.bak"
echo -e "\033[0;32m ✓ Updated Dockerfile with region: $CURRENT_REGION\033[0m"
else
echo -e "\033[0;33m ⚠ Dockerfile not found at $DOCKERFILE_PATH, skipping region update...\033[0m"
fi
# Step 5: Install CDK dependencies
echo -e "\n\033[0;33m[5/11] Installing CDK dependencies...\033[0m"
echo -e "\033[0;90m (Installing AWS CDK libraries and TypeScript packages for infrastructure code)\033[0m"
if [ ! -d "cdk/node_modules" ]; then
cd cdk
npm install
cd ..
else
echo -e "\033[0;90m CDK dependencies already installed, skipping...\033[0m"
fi
# Step 6: Install frontend dependencies
echo -e "\n\033[0;33m[6/11] Installing frontend dependencies...\033[0m"
echo -e "\033[0;90m (Installing React, Vite, Cognito SDK, and UI component libraries)\033[0m"
cd frontend
npm install
cd ..
# Step 7: Create placeholder dist
echo -e "\n\033[0;33m[7/11] Creating placeholder frontend build...\033[0m"
echo -e "\033[0;90m (Generating temporary HTML file - required for CDK synthesis)\033[0m"
if [ ! -d "frontend/dist" ]; then
mkdir -p frontend/dist
echo '<!DOCTYPE html><html><body><h1>Building...</h1></body></html>' > frontend/dist/index.html
else
echo -e "\033[0;90m Placeholder already exists, skipping...\033[0m"
fi
# Step 8: Bootstrap CDK
echo -e "\n\033[0;33m[8/11] Bootstrapping CDK environment...\033[0m"
echo -e "\033[0;90m (Setting up CDK deployment resources in your AWS account/region)\033[0m"
cd cdk
TIMESTAMP=$(date +%Y%m%d%H%M%S)
npx cdk bootstrap --output "cdk.out.$TIMESTAMP" --no-cli-pager
if [ $? -ne 0 ]; then
echo -e "\033[0;31mCDK bootstrap failed\033[0m"
exit 1
fi
cd ..
# Step 9: Deploy infrastructure stack
echo -e "\n\033[0;33m[9/11] Deploying infrastructure stack...\033[0m"
echo -e "\033[0;90m (Creating ECR repository, CodeBuild project, S3 bucket, and IAM roles)\033[0m"
echo -e "\033[0;90m Note: Nova Sonic model calls use BEDROCK_REGION=us-east-1 by default.\033[0m"
echo -e "\033[0;90m To change, update BEDROCK_REGION in cdk/lib/runtime-stack.ts before deploying.\033[0m"
echo -e "\033[0;90m See supported regions: https://docs.aws.amazon.com/bedrock/latest/userguide/models-regions.html\033[0m"
cd cdk
TIMESTAMP=$(date +%Y%m%d%H%M%S)
npx cdk deploy AgentCoreNovaSonicBidiInfra-$CURRENT_REGION --output "cdk.out.$TIMESTAMP" --no-cli-pager --require-approval never
if [ $? -ne 0 ]; then
echo -e "\033[0;31mInfrastructure deployment failed\033[0m"
exit 1
fi
cd ..
# Step 10: Deploy auth stack
echo -e "\n\033[0;33m[10/11] Deploying authentication stack...\033[0m"
echo -e "\033[0;90m (Creating Cognito User Pool with email verification and password policies)\033[0m"
cd cdk
TIMESTAMP=$(date +%Y%m%d%H%M%S)
npx cdk deploy AgentCoreNovaSonicBidiAuth-$CURRENT_REGION --output "cdk.out.$TIMESTAMP" --no-cli-pager --require-approval never
if [ $? -ne 0 ]; then
echo -e "\033[0;31mAuth deployment failed\033[0m"
exit 1
fi
cd ..
# Step 11: Deploy backend stack
echo -e "\n\033[0;33m[11/11] Deploying AgentCore backend stack...\033[0m"
echo -e "\033[0;90m (Uploading agent code, building ARM64 Docker image, creating AgentCore runtime with built-in Cognito auth)\033[0m"
echo -e "\033[0;90m Note: CodeBuild will compile the container image - this takes 5-10 minutes\033[0m"
echo -e "\033[0;90m The deployment will pause while waiting for the build to complete...\033[0m"
cd cdk
TIMESTAMP=$(date +%Y%m%d%H%M%S)
CDK_OUTPUT=$(npx cdk deploy AgentCoreNovaSonicBidiRuntime-$CURRENT_REGION --output "cdk.out.$TIMESTAMP" --no-cli-pager --require-approval never 2>&1)
CDK_EXIT=$?
echo "$CDK_OUTPUT"
cd ..
if [ $CDK_EXIT -ne 0 ]; then
if echo "$CDK_OUTPUT" | grep -q "Unrecognized resource types.*BedrockAgentCore"; then
CURRENT_REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-unknown}}
echo -e "\n\033[0;31m❌ DEPLOYMENT FAILED: AgentCore is not available in region '$CURRENT_REGION'\033[0m"
echo ""
echo -e "\033[0;33mPlease verify AgentCore availability in your target region:\033[0m"
echo -e "\033[0;36mhttps://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/agentcore-regions.html\033[0m"
echo ""
echo -e "\033[0;33mTo deploy to a supported region, set the AWS_DEFAULT_REGION environment variable:\033[0m"
echo -e "\033[0;90m export AWS_DEFAULT_REGION=\"your-supported-region\"\033[0m"
echo -e "\033[0;90m export AWS_REGION=\"your-supported-region\"\033[0m"
echo -e "\033[0;90m ./deploy-all.sh\033[0m"
exit 1
fi
echo -e "\033[0;31mBackend deployment failed\033[0m"
exit 1
fi
# Build and deploy frontend
echo -e "\nBuilding and deploying frontend..."
echo -e "\033[0;90m (Retrieving AgentCore Runtime ID and Cognito config, building React app, deploying to S3 + CloudFront)\033[0m"
AGENT_RUNTIME_ARN=$(aws cloudformation describe-stacks --stack-name AgentCoreNovaSonicBidiRuntime-$CURRENT_REGION --region "$CURRENT_REGION" --query "Stacks[0].Outputs[?OutputKey=='AgentRuntimeArn'].OutputValue" --output text --no-cli-pager)
REGION=$(aws cloudformation describe-stacks --stack-name AgentCoreNovaSonicBidiRuntime-$CURRENT_REGION --region "$CURRENT_REGION" --query "Stacks[0].Outputs[?OutputKey=='Region'].OutputValue" --output text --no-cli-pager)
USER_POOL_ID=$(aws cloudformation describe-stacks --stack-name AgentCoreNovaSonicBidiAuth-$CURRENT_REGION --region "$CURRENT_REGION" --query "Stacks[0].Outputs[?OutputKey=='UserPoolId'].OutputValue" --output text --no-cli-pager)
USER_POOL_CLIENT_ID=$(aws cloudformation describe-stacks --stack-name AgentCoreNovaSonicBidiAuth-$CURRENT_REGION --region "$CURRENT_REGION" --query "Stacks[0].Outputs[?OutputKey=='UserPoolClientId'].OutputValue" --output text --no-cli-pager)
IDENTITY_POOL_ID=$(aws cloudformation describe-stacks --stack-name AgentCoreNovaSonicBidiAuth-$CURRENT_REGION --region "$CURRENT_REGION" --query "Stacks[0].Outputs[?OutputKey=='IdentityPoolId'].OutputValue" --output text --no-cli-pager)
if [ -z "$AGENT_RUNTIME_ARN" ]; then
echo -e "\033[0;31mFailed to get Agent Runtime ARN from stack outputs\033[0m"
exit 1
fi
if [ -z "$REGION" ]; then
echo -e "\033[0;31mFailed to get Region from stack outputs\033[0m"
exit 1
fi
if [ -z "$USER_POOL_ID" ] || [ -z "$USER_POOL_CLIENT_ID" ] || [ -z "$IDENTITY_POOL_ID" ]; then
echo -e "\033[0;31mFailed to get Cognito config from stack outputs\033[0m"
exit 1
fi
echo -e "\033[0;32mAgent Runtime ARN: $AGENT_RUNTIME_ARN\033[0m"
echo -e "\033[0;32mRegion: $REGION\033[0m"
echo -e "\033[0;32mUser Pool ID: $USER_POOL_ID\033[0m"
echo -e "\033[0;32mUser Pool Client ID: $USER_POOL_CLIENT_ID\033[0m"
echo -e "\033[0;32mIdentity Pool ID: $IDENTITY_POOL_ID\033[0m"
# Build frontend
./scripts/build-frontend.sh "$USER_POOL_ID" "$USER_POOL_CLIENT_ID" "$IDENTITY_POOL_ID" "$AGENT_RUNTIME_ARN" "$REGION"
if [ $? -ne 0 ]; then
echo -e "\033[0;31mFrontend build failed\033[0m"
exit 1
fi
# Deploy frontend stack
cd cdk
TIMESTAMP=$(date +%Y%m%d%H%M%S)
npx cdk deploy AgentCoreNovaSonicBidiFrontend-$CURRENT_REGION --output "cdk.out.$TIMESTAMP" --no-cli-pager --require-approval never
if [ $? -ne 0 ]; then
echo -e "\033[0;31mFrontend deployment failed\033[0m"
exit 1
fi
cd ..
# Get CloudFront URL
WEBSITE_URL=$(aws cloudformation describe-stacks --stack-name AgentCoreNovaSonicBidiFrontend-$CURRENT_REGION --region "$CURRENT_REGION" --query "Stacks[0].Outputs[?OutputKey=='WebsiteUrl'].OutputValue" --output text --no-cli-pager)
echo -e "\n\033[0;32m=== Deployment Complete ===\033[0m"
echo -e "\033[0;36mWebsite URL: $WEBSITE_URL\033[0m"
echo -e "\033[0;36mAgent Runtime ARN: $AGENT_RUNTIME_ARN\033[0m"
echo -e "\033[0;36mRegion: $REGION\033[0m"
echo -e "\033[0;36mUser Pool ID: $USER_POOL_ID\033[0m"
echo -e "\033[0;36mUser Pool Client ID: $USER_POOL_CLIENT_ID\033[0m"
echo -e "\033[0;36mIdentity Pool ID: $IDENTITY_POOL_ID\033[0m"
echo -e "\n\033[0;33mNote: Users must sign up and log in to use the application\033[0m"