Improving the launch script to already update the server .env file.

This commit is contained in:
Filipi Fuchter
2025-12-01 07:43:29 -03:00
parent 75765a876b
commit 21ced5ba68

View File

@@ -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"
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: <value>
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"