From 21ced5ba6840b7a4d167e886a2df82006747c9fb Mon Sep 17 00:00:00 2001 From: Filipi Fuchter Date: Mon, 1 Dec 2025 07:43:29 -0300 Subject: [PATCH] Improving the launch script to already update the server .env file. --- .../agents/pipecat/scripts/launch.sh | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/examples/aws-agentcore/agents/pipecat/scripts/launch.sh b/examples/aws-agentcore/agents/pipecat/scripts/launch.sh index f3f676a3a..66d28ccb3 100755 --- a/examples/aws-agentcore/agents/pipecat/scripts/launch.sh +++ b/examples/aws-agentcore/agents/pipecat/scripts/launch.sh @@ -1,8 +1,14 @@ #!/bin/bash # Script to dynamically read all variables from .env file and launch agentcore +YAML_FILE=".bedrock_agentcore.yaml" +SERVER_ENV_FILE="../../server/.env" -# Check if .env file exists +############################################### +# STEP 1 — Launch the new agent +############################################### + +# Check if the local .env file exists if [ ! -f ".env" ]; then echo "Error: .env file not found in current directory" echo "Please create a .env file with your environment variables" @@ -52,4 +58,44 @@ fi # Execute the command echo "" echo "Executing: $LAUNCH_CMD" -eval "$LAUNCH_CMD" \ No newline at end of file +eval "$LAUNCH_CMD" + + +############################################### +# STEP 2 — Extract AGENT ARN from YAML +############################################### +if [ ! -f "$YAML_FILE" ]; then + echo "ERROR: $YAML_FILE not found!" + exit 1 +fi + +# Extracts: agent_arn: +AGENT_ARN=$(grep -E "^\s*agent_arn:" "$YAML_FILE" | awk '{print $2}') + +# Wait until it exists +while [ -z "$AGENT_ARN" ]; do + sleep 0.2 + AGENT_ARN=$(grep -E "^\s*agent_arn:" "$YAML_FILE" | awk '{print $2}') +done + +echo "Extracted Agent ARN: $AGENT_ARN" + +############################################### +# STEP 3 — Update server .env +############################################### +if [ ! -f "$SERVER_ENV_FILE" ]; then + echo "ERROR: $SERVER_ENV_FILE not found!" + exit 1 +fi + +# If AGENT_RUNTIME_ARN already exists → replace +# If not → append +if grep -q "^AGENT_RUNTIME_ARN=" "$SERVER_ENV_FILE"; then + sed -i.bak "s|^AGENT_RUNTIME_ARN=.*|AGENT_RUNTIME_ARN=$AGENT_ARN|" "$SERVER_ENV_FILE" +else + echo "AGENT_RUNTIME_ARN=$AGENT_ARN" >> "$SERVER_ENV_FILE" +fi + +echo ".env updated successfully!" +echo "AGENT_RUNTIME_ARN is now set to:" +echo "$AGENT_ARN" \ No newline at end of file