-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
Β·216 lines (200 loc) Β· 9.43 KB
/
deploy.sh
File metadata and controls
executable file
Β·216 lines (200 loc) Β· 9.43 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
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/.env"
source "$SCRIPT_DIR/.venv/bin/activate"
SQL_SERVER_DIR="$SCRIPT_DIR/db-engines/sql-server"
# Step 0: Create shared memory with semantic + summarization strategies
echo "π§ Setting up shared memory..."
MEMORY_ID=$(python3 "$SCRIPT_DIR/scripts/setup_memory.py" | grep "^MEMORY_ID=" | cut -d= -f2)
if [ -z "$MEMORY_ID" ]; then
echo "β Failed to create shared memory"
exit 1
fi
echo ""
STAGE=$(mktemp -d)
trap "rm -rf $STAGE" EXIT
cp -r "$SQL_SERVER_DIR/config" "$STAGE/config"
cp -r "$SQL_SERVER_DIR/tools" "$STAGE/tools"
cp "$SQL_SERVER_DIR/requirements.txt" "$STAGE/"
for f in database_health_agent.py query_performance_agent.py security_audit_agent.py data_lifecycle_agent.py supervisor_agent.py; do
cp "$SQL_SERVER_DIR/agents/$f" "$STAGE/"
done
cd "$STAGE"
COMMON="--deployment-type direct_code_deploy --non-interactive --disable-memory --vpc --subnets $SUBNET1 --security-groups $SECURITY_GROUP_ID --execution-role $AGENTCORE_ROLE_ARN"
# Pre-flight: detect stale agents from a different VPC/subnet
# When --auto-update-on-conflict changes VPC config, endpoints aren't recreated,
# leaving agents in READY state but unable to receive invocations.
echo "π Checking for stale agents from a different VPC..."
STALE_AGENTS=$(python3 -c "
import boto3, json
client = boto3.client('bedrock-agentcore-control', region_name='$AWS_REGION')
names = ['database_health_agent','query_performance_agent','security_audit_agent','data_lifecycle_agent','supervisor_agent']
runtimes = client.list_agent_runtimes(maxResults=50).get('agentRuntimes', [])
for r in runtimes:
if r['agentRuntimeName'] in names:
rt = client.get_agent_runtime(agentRuntimeId=r['agentRuntimeId'])
nc = rt.get('networkConfiguration', {}).get('networkModeConfig', {})
subnets = nc.get('subnets', [])
if '$SUBNET1' not in subnets:
print(r['agentRuntimeId'])
" 2>/dev/null)
if [ -n "$STALE_AGENTS" ]; then
echo " β οΈ Found agents deployed to a different subnet. Deleting stale agents..."
echo " (--auto-update-on-conflict doesn't recreate endpoints when VPC changes)"
for STALE_ID in $STALE_AGENTS; do
echo " Deleting $STALE_ID..."
python3 -c "
import boto3
boto3.client('bedrock-agentcore-control', region_name='$AWS_REGION').delete_agent_runtime(agentRuntimeId='$STALE_ID')
print(' β
Deleted')
" 2>/dev/null
done
echo ""
else
echo " β
No stale agents found"
echo ""
fi
echo "π₯ [1/5] Database Health Agent..."
agentcore configure --name database_health_agent -e database_health_agent.py $COMMON
agentcore deploy --agent database_health_agent --auto-update-on-conflict \
--env MEMORY_ID=$MEMORY_ID --env DB_INSTANCE_ID=$DB_INSTANCE_ID \
--env SNS_TOPIC_NAME=$SNS_TOPIC_NAME --env AWS_REGION=$AWS_REGION
echo "β
Database Health Agent deployed"
echo "β‘ [2/5] Query Performance Agent..."
agentcore configure --name query_performance_agent -e query_performance_agent.py $COMMON
agentcore deploy --agent query_performance_agent --auto-update-on-conflict \
--env MEMORY_ID=$MEMORY_ID --env DB_INSTANCE_ID=$DB_INSTANCE_ID \
--env DB_SECRET_ID=$DB_SECRET_ID --env SNS_TOPIC_NAME=$SNS_TOPIC_NAME --env AWS_REGION=$AWS_REGION
echo "β
Query Performance Agent deployed"
echo "π [3/5] Security Audit Agent..."
agentcore configure --name security_audit_agent -e security_audit_agent.py $COMMON
agentcore deploy --agent security_audit_agent --auto-update-on-conflict \
--env MEMORY_ID=$MEMORY_ID --env DB_INSTANCE_ID=$DB_INSTANCE_ID \
--env DB_SECRET_ID=$DB_SECRET_ID --env SNS_TOPIC_NAME=$SNS_TOPIC_NAME --env AWS_REGION=$AWS_REGION
echo "β
Security Audit Agent deployed"
echo "πΎ [4/5] Data Lifecycle Agent..."
agentcore configure --name data_lifecycle_agent -e data_lifecycle_agent.py $COMMON
agentcore deploy --agent data_lifecycle_agent --auto-update-on-conflict \
--env MEMORY_ID=$MEMORY_ID --env DB_INSTANCE_ID=$DB_INSTANCE_ID \
--env DB_SECRET_ID=$DB_SECRET_ID --env SNS_TOPIC_NAME=$SNS_TOPIC_NAME --env AWS_REGION=$AWS_REGION
echo "β
Data Lifecycle Agent deployed"
echo "π― [5/5] Supervisor Agent..."
# Look up fresh sub-agent ARNs (they change on each deploy)
echo " Resolving sub-agent ARNs..."
AGENT_ARNS=$(python3 -c "
import boto3
client = boto3.client('bedrock-agentcore-control', region_name='$AWS_REGION')
runtimes = client.list_agent_runtimes(maxResults=50).get('agentRuntimes', [])
mapping = {'database_health_agent':'HEALTH', 'query_performance_agent':'PERFORMANCE', 'security_audit_agent':'SECURITY', 'data_lifecycle_agent':'LIFECYCLE'}
for r in runtimes:
prefix = mapping.get(r['agentRuntimeName'])
if prefix:
print(f\"{prefix}_AGENT_ARN={r['agentRuntimeArn']}\")
")
eval "$AGENT_ARNS"
echo " HEALTH_AGENT_ARN=$HEALTH_AGENT_ARN"
echo " PERFORMANCE_AGENT_ARN=$PERFORMANCE_AGENT_ARN"
echo " SECURITY_AGENT_ARN=$SECURITY_AGENT_ARN"
echo " LIFECYCLE_AGENT_ARN=$LIFECYCLE_AGENT_ARN"
agentcore configure --name supervisor_agent -e supervisor_agent.py $COMMON
agentcore deploy --agent supervisor_agent --auto-update-on-conflict \
--env MEMORY_ID=$MEMORY_ID --env SNS_TOPIC_NAME=$SNS_TOPIC_NAME --env AWS_REGION=$AWS_REGION \
--env HEALTH_AGENT_ARN=$HEALTH_AGENT_ARN --env PERFORMANCE_AGENT_ARN=$PERFORMANCE_AGENT_ARN \
--env SECURITY_AGENT_ARN=$SECURITY_AGENT_ARN --env LIFECYCLE_AGENT_ARN=$LIFECYCLE_AGENT_ARN
echo "β
Supervisor Agent deployed"
# Update .env with fresh agent ARNs
echo "π Updating .env with new agent ARNs..."
ENV_FILE="$SCRIPT_DIR/.env"
ALL_ARNS=$(python3 -c "
import boto3
client = boto3.client('bedrock-agentcore-control', region_name='$AWS_REGION')
runtimes = client.list_agent_runtimes(maxResults=50).get('agentRuntimes', [])
mapping = {
'database_health_agent': 'HEALTH_AGENT_ARN',
'query_performance_agent': 'PERFORMANCE_AGENT_ARN',
'security_audit_agent': 'SECURITY_AGENT_ARN',
'data_lifecycle_agent': 'LIFECYCLE_AGENT_ARN',
'supervisor_agent': 'SUPERVISOR_AGENT_ARN',
}
for r in runtimes:
key = mapping.get(r['agentRuntimeName'])
if key:
print(f\"{key}={r['agentRuntimeArn']}\")
")
while IFS='=' read -r key value; do
if grep -q "^export ${key}=" "$ENV_FILE"; then
sed -i '' "s|^export ${key}=.*|export ${key}=${value}|" "$ENV_FILE"
else
echo "export ${key}=${value}" >> "$ENV_FILE"
fi
done <<< "$ALL_ARNS"
echo " β
.env updated"
# Generate .bedrock_agentcore.yaml so `agentcore invoke --agent <name>` works from project root
echo "π Generating .bedrock_agentcore.yaml..."
python3 -c "
import boto3, yaml
client = boto3.client('bedrock-agentcore-control', region_name='$AWS_REGION')
runtimes = client.list_agent_runtimes(maxResults=50).get('agentRuntimes', [])
names = ['database_health_agent','query_performance_agent','security_audit_agent','data_lifecycle_agent','supervisor_agent']
agents = {}
for r in runtimes:
n = r['agentRuntimeName']
if n in names:
agents[n] = {
'name': n,
'entrypoint': n + '.py',
'deployment_type': 'direct_code_deploy',
'runtime_type': 'PYTHON_3_12',
'platform': 'linux/arm64',
'container_runtime': None,
'source_path': '$SCRIPT_DIR',
'aws': {
'execution_role': '$AGENTCORE_ROLE_ARN',
'execution_role_auto_create': True,
'account': '${AWS_ACCOUNT_ID:-123456789012}',
'region': '$AWS_REGION',
'ecr_repository': None,
'ecr_auto_create': False,
's3_path': None,
's3_auto_create': True,
'network_configuration': {
'network_mode': 'VPC',
'network_mode_config': {
'security_groups': ['$SECURITY_GROUP_ID'],
'subnets': ['$SUBNET1'],
},
},
'protocol_configuration': {'server_protocol': 'HTTP'},
'observability': {'enabled': True},
'lifecycle_configuration': {'idle_runtime_session_timeout': None, 'max_lifetime': None},
},
'bedrock_agentcore': {
'agent_id': r['agentRuntimeId'],
'agent_arn': r['agentRuntimeArn'],
'agent_session_id': None,
},
'codebuild': {'project_name': None, 'execution_role': None, 'source_bucket': None},
'memory': {
'mode': 'NO_MEMORY',
'memory_id': None, 'memory_arn': None, 'memory_name': None,
'event_expiry_days': 30,
'first_invoke_memory_check_done': False,
'was_created_by_toolkit': False,
},
'identity': {'credential_providers': [], 'workload': None},
'aws_jwt': {'enabled': False, 'audiences': [], 'signing_algorithm': 'ES384', 'issuer_url': None, 'duration_seconds': 300},
'authorizer_configuration': None,
'request_header_configuration': None,
'oauth_configuration': None,
'api_key_env_var_name': None,
'api_key_credential_provider_name': None,
'is_generated_by_agentcore_create': False,
}
config = {'default_agent': 'supervisor_agent', 'agents': agents}
with open('$SCRIPT_DIR/.bedrock_agentcore.yaml', 'w') as f:
yaml.dump(config, f, default_flow_style=False, sort_keys=False)
print(' β
.bedrock_agentcore.yaml generated')
"
echo ""
echo "π All 5 agents deployed to private subnet: $SUBNET1"