Skip to content

Commit beca45f

Browse files
committed
docs(readme): Enhance local development documentation and script (windows only)
- Update README.md with more detailed local development workflow - Add comprehensive explanation of how local agent development works - Improve section on development workflow and agent restart process - Update project structure description with more precise formatting - Enhance `dev-local.ps1` script with robust AWS credential and environment checks - Add detailed error handling and guidance for AWS CLI configuration - Include version compatibility checks for AWS CLI - Provide more informative console output during local development setup Rationale: Improve developer onboarding experience and provide clearer guidance for local development environment setup
1 parent 3424edf commit beca45f

File tree

2 files changed

+147
-36
lines changed

2 files changed

+147
-36
lines changed

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,24 @@ This will:
108108
5. Configure the frontend to call the local agent (no authentication required)
109109

110110
**Local Development Features:**
111-
- ✅ Hot reload for both frontend and agent changes
111+
- ✅ Frontend hot reload (Vite dev server)
112+
- ✅ Fast agent restart cycle (no deployment needed)
112113
- ✅ Authentication with Cognito is bypassed
113114
- ✅ Same agent code as production
114-
-Fast iteration cycle
115+
-Rapid iteration without AWS deployment
115116

116-
**Note:** Local development uses the same `strands_agent.py` file as production. Changes made locally will be reflected when you deploy.
117+
**How Local Development Works:**
118+
- `python strands_agent.py` starts your agent as a regular Python process
119+
- `app.run()` in `strands_agent.py` creates HTTP server on `localhost:8080` (via `bedrock-agentcore` library)
120+
- Frontend sends POST requests to `/api/invocations`
121+
- Agent executes directly in Python, calls AWS Bedrock APIs
122+
- No Docker, no containers needed - just Python + web server
123+
124+
**Development Workflow:**
125+
- **Frontend changes** (`frontend/` files): Hot reload automatically via Vite
126+
- **Agent changes** (`agent/` files): Restart required - Ctrl+C then re-run script
127+
128+
**Note:** Agent restart takes ~10 seconds vs ~10 minutes for production deployment.
117129

118130
## Stack Architecture
119131

@@ -128,13 +140,13 @@ This will:
128140

129141
```
130142
project-root/
131-
├── agent/ # Agent runtime code
143+
├── agent/ # Agent runtime code
132144
│ ├── strands_agent.py # Agent implementation (Strands framework)
133145
│ ├── requirements.txt # Python dependencies
134146
│ ├── Dockerfile # ARM64 container definition
135147
│ └── .dockerignore # Docker ignore patterns
136148
137-
├── cdk/ # Infrastructure as Code
149+
├── cdk/ # Infrastructure as Code
138150
│ ├── bin/
139151
│ │ └── app.ts # CDK app entry point
140152
│ ├── lib/
@@ -146,7 +158,7 @@ project-root/
146158
│ └── package.json # CDK dependencies
147159
148160
149-
├── frontend/ # React app (Vite)
161+
├── frontend/ # React app (Vite)
150162
│ ├── src/
151163
│ │ ├── App.tsx # Main UI component with auth
152164
│ │ ├── AuthModal.tsx # Login/signup modal
@@ -162,6 +174,8 @@ project-root/
162174
163175
├── deploy-all.ps1 # Main deployment orchestration (Windows)
164176
├── deploy-all.sh # Main deployment orchestration (macOS/Linux)
177+
├── dev-local.ps1 # Local development mode (Windows)
178+
├── dev-local.sh # Local development mode (macOS/Linux)
165179
└── README.md # This file
166180
```
167181

dev-local.ps1

Lines changed: 127 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,146 @@
11
# Local Development Script - Start frontend and AgentCore backend locally
22

3-
Write-Host "🚀 Starting Local Development Mode" -ForegroundColor Cyan
4-
Write-Host "==================================" -ForegroundColor Cyan
3+
Write-Host "=== Local Development Mode ===" -ForegroundColor Cyan
54

6-
# Check if Python is available
5+
# Step 1: Verify AWS credentials
6+
Write-Host "`n[1/7] Verifying AWS credentials..." -ForegroundColor Yellow
7+
Write-Host " (Required for AWS service access when running agent locally)" -ForegroundColor Gray
8+
9+
# Check if AWS credentials are configured
10+
$callerIdentity = aws sts get-caller-identity 2>&1
11+
12+
if ($LASTEXITCODE -ne 0) {
13+
Write-Host " ❌ AWS credentials are not configured or have expired" -ForegroundColor Red
14+
Write-Host "`nPlease configure AWS credentials using one of these methods:" -ForegroundColor Yellow
15+
Write-Host " 1. Run: aws configure" -ForegroundColor Cyan
16+
Write-Host " 2. Set environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY" -ForegroundColor Cyan
17+
Write-Host " 3. Use AWS SSO: aws sso login --profile <profile-name>" -ForegroundColor Cyan
18+
Write-Host "`nFor more info: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html" -ForegroundColor Gray
19+
exit 1
20+
}
21+
22+
# Display current AWS identity
23+
$accountId = ($callerIdentity | ConvertFrom-Json).Account
24+
$arn = ($callerIdentity | ConvertFrom-Json).Arn
25+
Write-Host " ✓ Authenticated as: $arn" -ForegroundColor Green
26+
Write-Host " AWS Account: $accountId" -ForegroundColor Green
27+
28+
# Step 2: Check AWS CLI version
29+
Write-Host "`n[2/7] Checking AWS CLI version..." -ForegroundColor Yellow
30+
Write-Host " (Ensuring compatibility with Bedrock service)" -ForegroundColor Gray
31+
$awsVersion = aws --version 2>&1
32+
$versionMatch = $awsVersion -match 'aws-cli/(\d+)\.(\d+)\.(\d+)'
33+
if ($versionMatch) {
34+
$major = [int]$Matches[1]
35+
$minor = [int]$Matches[2]
36+
$patch = [int]$Matches[3]
37+
Write-Host " Current version: aws-cli/$major.$minor.$patch" -ForegroundColor Gray
38+
39+
# Check if version is >= 2.31.13 (recommended for Bedrock)
40+
$isVersionValid = ($major -gt 2) -or
41+
($major -eq 2 -and $minor -gt 31) -or
42+
($major -eq 2 -and $minor -eq 31 -and $patch -ge 13)
43+
44+
if (-not $isVersionValid) {
45+
Write-Host " ⚠ AWS CLI version 2.31.13 or later is recommended for Bedrock" -ForegroundColor Yellow
46+
Write-Host " Your current version: aws-cli/$major.$minor.$patch" -ForegroundColor Yellow
47+
Write-Host " Consider upgrading: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html" -ForegroundColor Gray
48+
} else {
49+
Write-Host " ✓ AWS CLI version is compatible" -ForegroundColor Green
50+
}
51+
} else {
52+
Write-Host " ⚠ Could not parse AWS CLI version, continuing anyway..." -ForegroundColor Yellow
53+
}
54+
55+
# Step 3: Check AgentCore availability in current region
56+
Write-Host "`n[3/7] Checking AgentCore availability in current region..." -ForegroundColor Yellow
57+
Write-Host " (Verifying AgentCore service availability)" -ForegroundColor Gray
58+
# Detect current region from AWS CLI configuration
59+
$currentRegion = aws configure get region
60+
if ([string]::IsNullOrEmpty($currentRegion)) {
61+
Write-Host " ❌ No AWS region configured" -ForegroundColor Red
62+
Write-Host ""
63+
Write-Host " Please configure your AWS region using:" -ForegroundColor Yellow
64+
Write-Host " aws configure set region <your-region>" -ForegroundColor Cyan
65+
Write-Host ""
66+
Write-Host " For supported regions, see:" -ForegroundColor Gray
67+
Write-Host " https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-regions.html" -ForegroundColor Gray
68+
exit 1
69+
}
70+
Write-Host " Target region: $currentRegion" -ForegroundColor Gray
71+
72+
# Try to list AgentCore runtimes to verify service availability
73+
$agentCoreCheck = aws bedrock-agentcore-control list-agent-runtimes --region $currentRegion --max-results 1 2>&1
74+
if ($LASTEXITCODE -ne 0) {
75+
$errorMessage = $agentCoreCheck | Out-String
76+
Write-Host " ❌ AgentCore is not available in region: $currentRegion" -ForegroundColor Red
77+
Write-Host ""
78+
Write-Host " Error details:" -ForegroundColor Gray
79+
Write-Host " $errorMessage" -ForegroundColor DarkGray
80+
Write-Host ""
81+
Write-Host " For supported regions, see:" -ForegroundColor Gray
82+
Write-Host " https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-regions.html" -ForegroundColor Gray
83+
exit 1
84+
}
85+
Write-Host " ✓ AgentCore is available in $currentRegion" -ForegroundColor Green
86+
87+
# Step 4: Check Python availability
88+
Write-Host "`n[4/7] Checking Python installation..." -ForegroundColor Yellow
89+
Write-Host " (Required for running the agent locally)" -ForegroundColor Gray
790
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
8-
Write-Host "❌ Python 3 is required but not installed" -ForegroundColor Red
91+
Write-Host " ❌ Python 3.8+ is required but not installed" -ForegroundColor Red
92+
Write-Host ""
93+
Write-Host " Please install Python 3.8 or later:" -ForegroundColor Yellow
94+
Write-Host " https://www.python.org/downloads/" -ForegroundColor Cyan
995
exit 1
1096
}
1197

12-
# Check if Node.js is available
98+
$pythonVersion = python --version 2>&1
99+
Write-Host "$pythonVersion" -ForegroundColor Green
100+
101+
# Step 5: Check Node.js availability
102+
Write-Host "`n[5/7] Checking Node.js installation..." -ForegroundColor Yellow
103+
Write-Host " (Required for frontend development server)" -ForegroundColor Gray
13104
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
14-
Write-Host "❌ Node.js is required but not installed" -ForegroundColor Red
105+
Write-Host " ❌ Node.js 18+ is required but not installed" -ForegroundColor Red
106+
Write-Host ""
107+
Write-Host " Please install Node.js 18 or later:" -ForegroundColor Yellow
108+
Write-Host " https://nodejs.org/en/download/" -ForegroundColor Cyan
15109
exit 1
16110
}
17111

112+
$nodeVersion = node --version 2>&1
113+
Write-Host " ✓ Node.js $nodeVersion" -ForegroundColor Green
114+
115+
# Step 6: Install dependencies
116+
Write-Host "`n[6/7] Installing dependencies..." -ForegroundColor Yellow
117+
18118
# Install agent dependencies if needed
19-
Write-Host "📦 Installing agent dependencies..." -ForegroundColor Yellow
119+
Write-Host " Installing agent dependencies..." -ForegroundColor Gray
120+
Write-Host " (bedrock-agentcore for local HTTP server, strands-agents framework, boto3 for AWS)" -ForegroundColor DarkGray
20121
if (-not (Test-Path "agent/venv")) {
21-
Write-Host "Creating Python virtual environment..." -ForegroundColor Gray
122+
Write-Host " Creating Python virtual environment and installing dependencies..." -ForegroundColor DarkGray
22123
Push-Location agent
23124
python -m venv venv
24125
& "venv/Scripts/Activate.ps1"
25126
pip install -r requirements.txt
26127
Pop-Location
27128
} else {
28-
Write-Host "Virtual environment already exists" -ForegroundColor Gray
129+
Write-Host " Virtual environment already exists" -ForegroundColor DarkGray
29130
}
30131

31132
# Install frontend dependencies if needed
32-
Write-Host "📦 Installing frontend dependencies..." -ForegroundColor Yellow
133+
Write-Host " Installing frontend dependencies..." -ForegroundColor Gray
33134
Push-Location frontend
34135
if (-not (Test-Path "node_modules")) {
35136
npm install
137+
} else {
138+
Write-Host " Frontend dependencies already installed" -ForegroundColor DarkGray
36139
}
37140
Pop-Location
38141

39142
# Create local environment file for frontend
40-
Write-Host "⚙️ Setting up local environment..." -ForegroundColor Yellow
143+
Write-Host " Setting up local environment configuration..." -ForegroundColor Gray
41144

42145
# Remove any production environment file
43146
if (Test-Path "frontend/.env.production.local") {
@@ -49,37 +152,31 @@ VITE_LOCAL_DEV=true
49152
VITE_AGENT_RUNTIME_URL=/api
50153
"@ | Out-File -FilePath "frontend/.env.local" -Encoding UTF8
51154

52-
Write-Host "Created local development environment configuration" -ForegroundColor Gray
155+
Write-Host " ✓ Created local development environment configuration" -ForegroundColor Green
156+
157+
# Step 7: Start services
158+
Write-Host "`n[7/7] Starting local development services..." -ForegroundColor Yellow
53159

54160
Write-Host ""
55-
Write-Host "🎯 Starting services..." -ForegroundColor Green
56161
Write-Host "Backend will be available at: http://localhost:8080" -ForegroundColor Cyan
57162
Write-Host "Frontend will be available at: http://localhost:5173" -ForegroundColor Cyan
58163
Write-Host ""
164+
Write-Host "Development Workflow:" -ForegroundColor Yellow
165+
Write-Host " • Changes to frontend\ files → Immediate hot reload" -ForegroundColor Gray
166+
Write-Host " • Changes to agent\ files → Restart this script (Ctrl+C then re-run)" -ForegroundColor Gray
167+
Write-Host ""
59168
Write-Host "Press Ctrl+C to stop all services" -ForegroundColor Yellow
60169
Write-Host ""
61170

62171
# Start AgentCore backend in background
63-
Write-Host "🔧 Starting AgentCore backend..." -ForegroundColor Blue
64-
65-
# Check if AWS credentials are available
66-
$callerIdentity = aws sts get-caller-identity 2>&1
67-
if ($LASTEXITCODE -ne 0) {
68-
Write-Host "⚠️ AWS credentials not found. The agent needs AWS credentials to call Bedrock." -ForegroundColor Yellow
69-
Write-Host "Please configure AWS credentials using one of these methods:" -ForegroundColor Yellow
70-
Write-Host " 1. aws configure" -ForegroundColor Cyan
71-
Write-Host " 2. aws sso login --profile <profile-name>" -ForegroundColor Cyan
72-
Write-Host " 3. Set environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY" -ForegroundColor Cyan
73-
Write-Host ""
74-
Write-Host "Press Enter to continue anyway, or Ctrl+C to exit and configure credentials first..." -ForegroundColor Yellow
75-
Read-Host
76-
}
77-
172+
Write-Host "Starting AgentCore backend..." -ForegroundColor Blue
78173
Push-Location agent
79174
& "venv/Scripts/Activate.ps1"
80175
$backendJob = Start-Job -ScriptBlock {
81176
Set-Location $using:PWD/agent
82177
& "venv/Scripts/Activate.ps1"
178+
# Set UTF-8 encoding for Python to handle Unicode characters properly on Windows
179+
$env:PYTHONIOENCODING = "utf-8"
83180
python strands_agent.py
84181
}
85182
Pop-Location
@@ -88,7 +185,7 @@ Pop-Location
88185
Start-Sleep -Seconds 3
89186

90187
# Start frontend dev server in background
91-
Write-Host "🎨 Starting frontend dev server..." -ForegroundColor Magenta
188+
Write-Host "Starting frontend dev server..." -ForegroundColor Magenta
92189
Push-Location frontend
93190
$frontendJob = Start-Job -ScriptBlock {
94191
Set-Location $using:PWD/frontend
@@ -99,7 +196,7 @@ Pop-Location
99196
# Function to cleanup
100197
function Cleanup {
101198
Write-Host ""
102-
Write-Host "🛑 Stopping services..." -ForegroundColor Red
199+
Write-Host "`nStopping services..." -ForegroundColor Red
103200
Stop-Job $backendJob, $frontendJob -ErrorAction SilentlyContinue
104201
Remove-Job $backendJob, $frontendJob -ErrorAction SilentlyContinue
105202
}

0 commit comments

Comments
 (0)