Skip to content

Commit b72a000

Browse files
author
Yuriy Bezsonov
committed
feat(java-spring-ai-agents): add runtime update logic for existing agents
1 parent 1602a7b commit b72a000

2 files changed

Lines changed: 49 additions & 10 deletions

File tree

apps/java-spring-ai-agents/scripts/05-mcp-runtime.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,27 @@ EXISTING_RUNTIME_ID=$(aws bedrock-agentcore-control list-agent-runtimes \
173173

174174
if [ "${EXISTING_RUNTIME_ID}" != "None" ] && [ -n "${EXISTING_RUNTIME_ID}" ]; then
175175
echo "AgentCore Runtime already exists: ${EXISTING_RUNTIME_ID}"
176+
echo "Updating runtime with latest configuration..."
176177
MCP_RUNTIME_ID="${EXISTING_RUNTIME_ID}"
178+
179+
ROLE_ARN="arn:aws:iam::${ACCOUNT_ID}:role/backoffice-role"
180+
181+
aws bedrock-agentcore-control update-agent-runtime \
182+
--agent-runtime-id "${MCP_RUNTIME_ID}" \
183+
--role-arn "${ROLE_ARN}" \
184+
--agent-runtime-artifact "{\"containerConfiguration\":{\"containerUri\":\"${ECR_URI}:latest\"}}" \
185+
--protocol-configuration '{"serverProtocol":"MCP"}' \
186+
--network-configuration "{\"networkMode\":\"VPC\",\"networkModeConfig\":{\"subnets\":[\"${SUBNET_ID}\"],\"securityGroups\":[\"${SG_ID}\"]}}" \
187+
--authorizer-configuration "{\"customJWTAuthorizer\":{\"discoveryUrl\":\"${GATEWAY_DISCOVERY_URL}\",\"allowedClients\":[\"${GATEWAY_CLIENT_ID}\"]}}" \
188+
--region ${AWS_REGION} \
189+
--no-cli-pager
190+
191+
echo -n "Waiting for runtime"
192+
while [ "$(aws bedrock-agentcore-control get-agent-runtime \
193+
--agent-runtime-id "${MCP_RUNTIME_ID}" --region ${AWS_REGION} \
194+
--no-cli-pager --query 'status' --output text)" != "READY" ]; do
195+
echo -n "."; sleep 5
196+
done && echo " READY"
177197
else
178198
echo "Creating AgentCore Runtime: backoffice"
179199

apps/java-spring-ai-agents/scripts/08-aiagent-runtime.sh

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,8 @@ EXISTING_RUNTIME_ID=$(aws bedrock-agentcore-control list-agent-runtimes \
179179
--region ${AWS_REGION} --no-cli-pager \
180180
--query "agentRuntimes[?agentRuntimeName=='aiagent'].agentRuntimeId | [0]" --output text 2>/dev/null || echo "None")
181181

182-
if [ "${EXISTING_RUNTIME_ID}" != "None" ] && [ -n "${EXISTING_RUNTIME_ID}" ]; then
183-
echo "AgentCore Runtime already exists: ${EXISTING_RUNTIME_ID}"
184-
AIAGENT_RUNTIME_ID="${EXISTING_RUNTIME_ID}"
185-
else
186-
echo "Creating AgentCore Runtime: aiagent"
187-
188-
# Build environment variables JSON
189-
cat > /tmp/aiagent-env.json << EOF
182+
# Build environment variables JSON
183+
cat > /tmp/aiagent-env.json << EOF
190184
{
191185
"AGENTCORE_MEMORY_MEMORY_ID": "${AGENTCORE_MEMORY_MEMORY_ID}",
192186
"AGENTCORE_MEMORY_LONG_TERM_SEMANTIC_STRATEGY_ID": "${AGENTCORE_MEMORY_LONG_TERM_SEMANTIC_STRATEGY_ID}",
@@ -196,6 +190,31 @@ else
196190
}
197191
EOF
198192

193+
if [ "${EXISTING_RUNTIME_ID}" != "None" ] && [ -n "${EXISTING_RUNTIME_ID}" ]; then
194+
echo "AgentCore Runtime already exists: ${EXISTING_RUNTIME_ID}"
195+
echo "Updating runtime with latest configuration..."
196+
AIAGENT_RUNTIME_ID="${EXISTING_RUNTIME_ID}"
197+
198+
aws bedrock-agentcore-control update-agent-runtime \
199+
--agent-runtime-id "${AIAGENT_RUNTIME_ID}" \
200+
--role-arn "arn:aws:iam::${ACCOUNT_ID}:role/aiagent-runtime-role" \
201+
--agent-runtime-artifact "{\"containerConfiguration\":{\"containerUri\":\"${ECR_URI}:latest\"}}" \
202+
--network-configuration "{\"networkMode\":\"VPC\",\"networkModeConfig\":{\"subnets\":[\"${SUBNET_ID}\"],\"securityGroups\":[\"${SG_ID}\"]}}" \
203+
--authorizer-configuration "{\"customJWTAuthorizer\":{\"discoveryUrl\":\"${AIAGENT_DISCOVERY_URL}\",\"allowedClients\":[\"${AIAGENT_CLIENT_ID}\"]}}" \
204+
--request-header-configuration '{"requestHeaderAllowlist":["Authorization"]}' \
205+
--environment-variables file:///tmp/aiagent-env.json \
206+
--region ${AWS_REGION} \
207+
--no-cli-pager
208+
209+
echo -n "Waiting for runtime"
210+
while [ "$(aws bedrock-agentcore-control get-agent-runtime \
211+
--agent-runtime-id "${AIAGENT_RUNTIME_ID}" --region ${AWS_REGION} \
212+
--no-cli-pager --query 'status' --output text)" != "READY" ]; do
213+
echo -n "."; sleep 5
214+
done && echo " READY"
215+
else
216+
echo "Creating AgentCore Runtime: aiagent"
217+
199218
AIAGENT_RUNTIME_ID=$(aws bedrock-agentcore-control create-agent-runtime \
200219
--agent-runtime-name "aiagent" \
201220
--role-arn "arn:aws:iam::${ACCOUNT_ID}:role/aiagent-runtime-role" \
@@ -208,8 +227,6 @@ EOF
208227
--no-cli-pager \
209228
--query 'agentRuntimeId' --output text)
210229

211-
rm -f /tmp/aiagent-env.json
212-
213230
echo -n "Waiting for runtime"
214231
while [ "$(aws bedrock-agentcore-control get-agent-runtime \
215232
--agent-runtime-id "${AIAGENT_RUNTIME_ID}" --region ${AWS_REGION} \
@@ -218,6 +235,8 @@ EOF
218235
done && echo " READY"
219236
fi
220237

238+
rm -f /tmp/aiagent-env.json
239+
221240
# Save runtime ID to environment
222241
if ! grep -q "AIAGENT_RUNTIME_ID=${AIAGENT_RUNTIME_ID}" ~/environment/.envrc 2>/dev/null; then
223242
sed -i.bak '/AIAGENT_RUNTIME_ID=/d' ~/environment/.envrc 2>/dev/null || true

0 commit comments

Comments
 (0)