forked from awslabs/amazon-bedrock-agentcore-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·252 lines (202 loc) · 7.66 KB
/
deploy.sh
File metadata and controls
executable file
·252 lines (202 loc) · 7.66 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
#!/bin/bash
# ============================================================================
# Deploy Script for Multi-Agent Runtime (Terraform)
# ============================================================================
# This script automates the deployment process for the Multi-Agent Terraform configuration
# Usage: ./deploy.sh
set -e # Exit on error
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# ============================================================================
# Pre-flight Checks
# ============================================================================
print_info "Starting Multi-Agent Runtime Deployment..."
echo ""
# Check Terraform installation
if ! command_exists terraform; then
print_error "Terraform is not installed. Please install Terraform >= 1.6"
print_info "Visit: https://www.terraform.io/downloads"
exit 1
fi
# Check Terraform version
TERRAFORM_VERSION=$(terraform version -json | grep -o '"terraform_version":"[^"]*' | cut -d'"' -f4)
print_success "Terraform version: $TERRAFORM_VERSION"
# Check AWS CLI installation
if ! command_exists aws; then
print_error "AWS CLI is not installed. Please install and configure AWS CLI"
print_info "Visit: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html"
exit 1
fi
print_success "AWS CLI is installed"
# Check AWS credentials
if ! aws sts get-caller-identity > /dev/null 2>&1; then
print_error "AWS credentials are not configured or invalid"
print_info "Run: aws configure"
exit 1
fi
AWS_ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
AWS_REGION=$(aws configure get region)
print_success "AWS Account: $AWS_ACCOUNT"
print_success "AWS Region: $AWS_REGION"
echo ""
# ============================================================================
# Configuration Check
# ============================================================================
print_info "Checking configuration files..."
# Check if terraform.tfvars exists
if [ ! -f "terraform.tfvars" ]; then
print_warning "terraform.tfvars not found"
print_info "Creating terraform.tfvars from example..."
if [ -f "terraform.tfvars.example" ]; then
cp terraform.tfvars.example terraform.tfvars
print_success "Created terraform.tfvars"
print_warning "Please review and update terraform.tfvars with your settings"
print_info "Then run this script again"
exit 0
else
print_error "terraform.tfvars.example not found"
exit 1
fi
fi
print_success "Configuration file found: terraform.tfvars"
echo ""
# ============================================================================
# Terraform Initialization
# ============================================================================
print_info "Initializing Terraform..."
if terraform init; then
print_success "Terraform initialized successfully"
else
print_error "Terraform initialization failed"
exit 1
fi
echo ""
# ============================================================================
# Terraform Validation
# ============================================================================
print_info "Validating Terraform configuration..."
if terraform validate; then
print_success "Terraform configuration is valid"
else
print_error "Terraform validation failed"
exit 1
fi
echo ""
# ============================================================================
# Terraform Format Check
# ============================================================================
print_info "Checking Terraform formatting..."
if terraform fmt -check -recursive > /dev/null 2>&1; then
print_success "Terraform files are properly formatted"
else
print_warning "Some files need formatting. Running terraform fmt..."
terraform fmt -recursive
print_success "Files formatted"
fi
echo ""
# ============================================================================
# Terraform Plan
# ============================================================================
print_info "Creating Terraform execution plan..."
print_warning "This may take a few moments..."
echo ""
if terraform plan -out=tfplan; then
print_success "Terraform plan created successfully"
else
print_error "Terraform plan failed"
exit 1
fi
echo ""
# ============================================================================
# Deployment Confirmation
# ============================================================================
print_warning "========================================"
print_warning "DEPLOYMENT CONFIRMATION"
print_warning "========================================"
print_info "This will deploy the following resources:"
print_info " - 2x S3 Buckets (Orchestrator & Specialist source code storage)"
print_info " - 2x ECR Repositories (Orchestrator & Specialist)"
print_info " - 2x CodeBuild Projects (Orchestrator & Specialist)"
print_info " - IAM Roles and Policies (with A2A permissions)"
print_info " - Specialist Runtime (Independent)"
print_info " - Orchestrator Runtime (Depends on Specialist)"
echo ""
print_info "The deployment includes:"
print_info " - Building ARM64 Docker images for both agents"
print_info " - Creating AWS resources with proper dependencies"
print_info " - Setting up Agent-to-Agent (A2A) communication"
echo ""
read -p "Do you want to proceed with deployment? (yes/no): " -r
echo ""
if [[ ! $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then
print_info "Deployment cancelled by user"
rm -f tfplan
exit 0
fi
# ============================================================================
# Terraform Apply
# ============================================================================
print_info "Starting deployment..."
echo ""
if terraform apply tfplan; then
print_success "Deployment completed successfully!"
else
print_error "Deployment failed"
rm -f tfplan
exit 1
fi
# Clean up plan file
rm -f tfplan
echo ""
# ============================================================================
# Deployment Summary
# ============================================================================
print_success "========================================"
print_success "DEPLOYMENT COMPLETED"
print_success "========================================"
echo ""
print_info "Retrieving deployment outputs..."
echo ""
# Get outputs
ORCHESTRATOR_ID=$(terraform output -raw orchestrator_runtime_id 2>/dev/null || echo "N/A")
ORCHESTRATOR_ARN=$(terraform output -raw orchestrator_runtime_arn 2>/dev/null || echo "N/A")
SPECIALIST_ID=$(terraform output -raw specialist_runtime_id 2>/dev/null || echo "N/A")
SPECIALIST_ARN=$(terraform output -raw specialist_runtime_arn 2>/dev/null || echo "N/A")
print_success "Orchestrator Runtime ID: $ORCHESTRATOR_ID"
print_success "Orchestrator Runtime ARN: $ORCHESTRATOR_ARN"
echo ""
print_success "Specialist Runtime ID: $SPECIALIST_ID"
print_success "Specialist Runtime ARN: $SPECIALIST_ARN"
echo ""
print_info "Next Steps:"
print_info "1. Test the multi-agent system:"
print_info " python test_multi_agent.py"
echo ""
print_info "2. View all outputs (includes test commands):"
print_info " terraform output"
echo ""
print_info "3. Monitor in AWS Console:"
print_info " https://console.aws.amazon.com/bedrock/home?region=$AWS_REGION#/agentcore"
echo ""
print_success "Deployment completed successfully!"