@@ -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}
197191EOF
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" \
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} \
218235 done && echo " READY"
219236fi
220237
238+ rm -f /tmp/aiagent-env.json
239+
221240# Save runtime ID to environment
222241if ! 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