deploy_aws_nest.shβ’9.75 kB
#!/bin/bash
# Deploy Resume Agent to AWS EC2 within NEST
# Usage: bash deploy_aws_nest.sh <AGENT_ID> <REGISTRY_URL> [PORT] [REGION] [INSTANCE_TYPE] [KEY_NAME]
set -e
AGENT_ID="${1:-resume-agent}"
REGISTRY_URL="${2:-http://registry.chat39.com:6900}"
PORT="${3:-6050}"
REGION="${4:-us-east-1}"
INSTANCE_TYPE="${5:-t3.small}" # t3.small recommended (2GB RAM, 2 vCPU, CPU-optimized)
KEY_NAME="${6:-nanda-agent-key}"
SECURITY_GROUP="${7:-nanda-streamlined-agents}"
echo "==========================================================================="
echo "π AWS EC2 Resume Agent Deployment"
echo "==========================================================================="
echo "Agent ID: $AGENT_ID"
echo "Registry: $REGISTRY_URL"
echo "Port: $PORT"
echo "Region: $REGION"
echo "Instance Type: $INSTANCE_TYPE"
echo "Key Pair: $KEY_NAME"
echo "Security Group: $SECURITY_GROUP"
echo "==========================================================================="
echo ""
# Validate AWS CLI
if ! command -v aws &> /dev/null; then
echo "β AWS CLI not found. Please install it first:"
echo " https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html"
exit 1
fi
# Check AWS credentials
if ! aws sts get-caller-identity &> /dev/null; then
echo "β AWS credentials not configured. Run: aws configure"
exit 1
fi
echo "β
AWS credentials validated"
# Get Ubuntu 24.04 LTS AMI for the region
echo "[1/6] Finding Ubuntu 24.04 LTS AMI in $REGION..."
AMI_ID=$(aws ec2 describe-images \
--region "$REGION" \
--owners 099720109477 \
--filters "Name=name,Values=ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*" \
"Name=state,Values=available" \
--query 'Images | sort_by(@, &CreationDate) | [-1].ImageId' \
--output text)
if [ -z "$AMI_ID" ] || [ "$AMI_ID" = "None" ]; then
echo "β οΈ Ubuntu 24.04 not found, falling back to Ubuntu 22.04 LTS..."
AMI_ID="ami-0866a3c8686eaeeba" # Ubuntu 22.04 LTS (us-east-1)
fi
echo "β
Using AMI: $AMI_ID"
# Create user data script for EC2 instance
echo "[2/6] Preparing instance configuration..."
USER_DATA=$(cat <<'USERDATA_EOF'
#!/bin/bash
set -e
# Log everything
exec > >(tee -a /var/log/resume-agent-setup.log)
exec 2>&1
echo "=========================================="
echo "Resume Agent Setup - $(date)"
echo "=========================================="
# Update system
echo "[1/8] Updating system..."
export DEBIAN_FRONTEND=noninteractive
apt-get update -q
apt-get install -y -q python3 python3-pip python3-venv git curl supervisor
# Create application user
echo "[2/8] Creating application user..."
useradd -m -s /bin/bash resume || true
cd /home/resume
# Clone repositories
echo "[3/8] Cloning repositories..."
if [ ! -d "nest" ]; then
sudo -u resume git clone https://github.com/projnanda/NEST.git nest
fi
if [ ! -d "resume-agent" ]; then
sudo -u resume git clone https://github.com/vsiwach/MCP-Resume-AWS.git resume-agent
fi
# Setup Python virtual environment
echo "[4/8] Setting up Python environment..."
cd nest
sudo -u resume python3 -m venv env
sudo -u resume env/bin/pip install --upgrade pip setuptools wheel
# Install NEST
echo "[5/8] Installing NEST framework..."
sudo -u resume env/bin/pip install -e .
# Install resume agent dependencies (CPU-optimized)
echo "[6/8] Installing torch CPU-only first..."
cd /home/resume/resume-agent
sudo -u resume /home/resume/nest/env/bin/pip install --index-url https://download.pytorch.org/whl/cpu torch==2.3.0
echo "[7/8] Installing resume agent dependencies (CPU-only, no CUDA)..."
sudo -u resume /home/resume/nest/env/bin/pip install -r requirements.txt
# Create data directory
sudo -u resume mkdir -p data
# Note about resume files
cat > /home/resume/README_UPLOAD_RESUME.txt << 'README_EOF'
========================================
IMPORTANT: Upload Your Resume Files
========================================
To make the agent functional, you need to upload resume files:
1. SSH to this instance:
ssh -i YOUR_KEY.pem ubuntu@PUBLIC_IP
2. Upload resume files:
scp -i YOUR_KEY.pem resume.pdf ubuntu@PUBLIC_IP:/tmp/
3. Move to data directory:
sudo mv /tmp/resume.pdf /home/resume/resume-agent/data/
sudo chown resume:resume /home/resume/resume-agent/data/resume.pdf
4. Restart the agent:
sudo supervisorctl restart resume-agent
Supported formats: PDF, DOCX, TXT, MD
README_EOF
sudo chown resume:resume /home/resume/README_UPLOAD_RESUME.txt
# Get public IP
PUBLIC_IP=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)
# Configure environment
echo "[8/9] Configuring environment..."
cat > /home/resume/resume-agent/.env << ENV_EOF
AGENT_ID=AGENT_ID_PLACEHOLDER
PORT=PORT_PLACEHOLDER
REGISTRY_URL=REGISTRY_URL_PLACEHOLDER
PUBLIC_URL=http://${PUBLIC_IP}:PORT_PLACEHOLDER
DATA_DIR=/home/resume/resume-agent/data
ENV_EOF
sudo chown resume:resume /home/resume/resume-agent/.env
# Create supervisor configuration
echo "[9/9] Configuring supervisor..."
cat > /etc/supervisor/conf.d/resume-agent.conf << 'SUPERVISOR_EOF'
[program:resume-agent]
directory=/home/resume/resume-agent
command=/home/resume/nest/env/bin/python nest_resume_agent.py
user=resume
autostart=true
autorestart=true
startretries=10
redirect_stderr=true
stdout_logfile=/var/log/resume-agent.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=3
environment=HOME="/home/resume",USER="resume"
SUPERVISOR_EOF
# Reload supervisor
supervisorctl reread
supervisorctl update
# Wait a moment for service to start
sleep 5
echo ""
echo "=========================================="
echo "β
Resume Agent Deployment Complete!"
echo "=========================================="
echo "Agent URL: http://${PUBLIC_IP}:PORT_PLACEHOLDER/a2a"
echo ""
echo "β οΈ IMPORTANT: Upload resume files to activate the agent"
echo " See: /home/resume/README_UPLOAD_RESUME.txt"
echo ""
echo "View logs: tail -f /var/log/resume-agent.log"
echo "Check status: supervisorctl status resume-agent"
echo "=========================================="
USERDATA_EOF
)
# Replace placeholders
USER_DATA="${USER_DATA//AGENT_ID_PLACEHOLDER/$AGENT_ID}"
USER_DATA="${USER_DATA//PORT_PLACEHOLDER/$PORT}"
USER_DATA="${USER_DATA//REGISTRY_URL_PLACEHOLDER/$REGISTRY_URL}"
# Launch EC2 instance
echo "[3/6] Launching EC2 instance..."
INSTANCE_ID=$(aws ec2 run-instances \
--image-id "$AMI_ID" \
--instance-type "$INSTANCE_TYPE" \
--key-name "$KEY_NAME" \
--security-group-ids "$SECURITY_GROUP" \
--block-device-mappings '[{"DeviceName":"/dev/sda1","Ebs":{"VolumeSize":20,"VolumeType":"gp3"}}]' \
--user-data "$USER_DATA" \
--region "$REGION" \
--tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=nest-resume-$AGENT_ID},{Key=Type,Value=NEST-Resume-Agent},{Key=Port,Value=$PORT}]" \
--query 'Instances[0].InstanceId' \
--output text)
if [ -z "$INSTANCE_ID" ] || [ "$INSTANCE_ID" = "None" ]; then
echo "β Failed to launch EC2 instance"
exit 1
fi
echo "β
Instance created: $INSTANCE_ID"
# Wait for instance to be running
echo "[4/6] Waiting for instance to start (this may take 30-60 seconds)..."
aws ec2 wait instance-running --instance-ids "$INSTANCE_ID" --region "$REGION"
# Get public IP
PUBLIC_IP=$(aws ec2 describe-instances \
--instance-ids "$INSTANCE_ID" \
--region "$REGION" \
--query 'Reservations[0].Instances[0].PublicIpAddress' \
--output text)
echo "β
Instance running at: $PUBLIC_IP"
# Open port in security group
echo "[5/6] Configuring security group..."
aws ec2 authorize-security-group-ingress \
--group-id "$SECURITY_GROUP" \
--protocol tcp \
--port "$PORT" \
--cidr 0.0.0.0/0 \
--region "$REGION" 2>/dev/null && echo "β
Port $PORT opened" || echo "βΉοΈ Port $PORT already open"
echo "[6/6] Finalizing deployment..."
sleep 5
echo ""
echo "==========================================================================="
echo "β
Deployment Complete!"
echo "==========================================================================="
echo "Instance ID: $INSTANCE_ID"
echo "Public IP: $PUBLIC_IP"
echo "Agent URL: http://$PUBLIC_IP:$PORT/a2a"
echo "Agent ID: $AGENT_ID"
echo "Registry: $REGISTRY_URL"
echo "==========================================================================="
echo ""
echo "π Next Steps:"
echo "==========================================================================="
echo ""
echo "1. Wait 2-3 minutes for setup to complete, then check status:"
echo " ssh -i $KEY_NAME.pem ubuntu@$PUBLIC_IP"
echo " sudo tail -f /var/log/resume-agent-setup.log"
echo ""
echo "2. β οΈ UPLOAD RESUME FILES (Required for agent to work):"
echo " scp -i $KEY_NAME.pem resume.pdf ubuntu@$PUBLIC_IP:/tmp/"
echo " ssh -i $KEY_NAME.pem ubuntu@$PUBLIC_IP"
echo " sudo mv /tmp/resume.pdf /home/resume/resume-agent/data/"
echo " sudo chown resume:resume /home/resume/resume-agent/data/resume.pdf"
echo " sudo supervisorctl restart resume-agent"
echo ""
echo "3. Check agent status:"
echo " sudo supervisorctl status resume-agent"
echo " sudo tail -f /var/log/resume-agent.log"
echo ""
echo "4. Test the agent:"
echo " curl -X POST http://$PUBLIC_IP:$PORT/a2a \\"
echo " -H 'Content-Type: application/json' \\"
echo " -d '{\"content\":{\"text\":\"/info\",\"type\":\"text\"},\"role\":\"user\",\"conversation_id\":\"test\"}'"
echo ""
echo "==========================================================================="
echo "π° Cost Estimate: t3.small = ~\$0.02/hour (~\$15/month)"
echo "π To terminate: aws ec2 terminate-instances --instance-ids $INSTANCE_ID --region $REGION"
echo "==========================================================================="