Skip to content

Commit 0f6cca3

Browse files
committed
chore(deploy): Add Dockerfile region update step to deployment scripts
- Update step numbering from 10 to 11 in both deploy-all.ps1 and deploy-all.sh - Add new Step 4 to dynamically update Dockerfile with current AWS region - Set AWS_REGION and AWS_DEFAULT_REGION environment variables in agent/Dockerfile - Renumber subsequent deployment steps (5-11) to accommodate new region update step - Include error handling for missing Dockerfile with graceful fallback - Add descriptive output messages for the new region update process - Ensures Docker image is built with correct region configuration matching AWS CLI setup
1 parent 1b20461 commit 0f6cca3

2 files changed

Lines changed: 61 additions & 24 deletions

File tree

deploy-all.ps1

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Write-Host "=== AgentCore Demo Deployment ===" -ForegroundColor Cyan
44

55
# Step 1: Verify AWS credentials
6-
Write-Host "`n[1/10] Verifying AWS credentials..." -ForegroundColor Yellow
6+
Write-Host "`n[1/11] Verifying AWS credentials..." -ForegroundColor Yellow
77
Write-Host " (Checking AWS CLI configuration and validating access)" -ForegroundColor Gray
88

99
# Check if AWS credentials are configured
@@ -26,7 +26,7 @@ Write-Host " Authenticated as: $arn" -ForegroundColor Green
2626
Write-Host " AWS Account: $accountId" -ForegroundColor Green
2727

2828
# Step 2: Check AWS CLI version
29-
Write-Host "`n[2/10] Checking AWS CLI version..." -ForegroundColor Yellow
29+
Write-Host "`n[2/11] Checking AWS CLI version..." -ForegroundColor Yellow
3030
$awsVersion = aws --version 2>&1
3131
$versionMatch = $awsVersion -match 'aws-cli/(\d+)\.(\d+)\.(\d+)'
3232
if ($versionMatch) {
@@ -56,7 +56,7 @@ if ($versionMatch) {
5656
}
5757

5858
# Step 3: Check AgentCore availability in current region
59-
Write-Host "`n[3/10] Checking AgentCore availability in current region..." -ForegroundColor Yellow
59+
Write-Host "`n[3/11] Checking AgentCore availability in current region..." -ForegroundColor Yellow
6060
# Detect current region from AWS CLI configuration
6161
$currentRegion = aws configure get region
6262
if ([string]::IsNullOrEmpty($currentRegion)) {
@@ -86,8 +86,27 @@ if ($LASTEXITCODE -ne 0) {
8686
}
8787
Write-Host " ✓ AgentCore is available in $currentRegion" -ForegroundColor Green
8888

89-
# Step 4: Install CDK dependencies
90-
Write-Host "`n[4/10] Installing CDK dependencies..." -ForegroundColor Yellow
89+
# Step 4: Update Dockerfile with current region
90+
Write-Host "`n[4/11] Updating Dockerfile with current region..." -ForegroundColor Yellow
91+
Write-Host " (Setting AWS_REGION and AWS_DEFAULT_REGION to $currentRegion in agent/Dockerfile)" -ForegroundColor Gray
92+
93+
$dockerfilePath = "agent/Dockerfile"
94+
if (Test-Path $dockerfilePath) {
95+
$dockerfileContent = Get-Content $dockerfilePath -Raw
96+
97+
# Replace both AWS_REGION and AWS_DEFAULT_REGION with current region
98+
$dockerfileContent = $dockerfileContent -replace 'AWS_REGION=[\w-]+', "AWS_REGION=$currentRegion"
99+
$dockerfileContent = $dockerfileContent -replace 'AWS_DEFAULT_REGION=[\w-]+', "AWS_DEFAULT_REGION=$currentRegion"
100+
101+
# Write back to file
102+
Set-Content -Path $dockerfilePath -Value $dockerfileContent -NoNewline
103+
Write-Host " ✓ Updated Dockerfile with region: $currentRegion" -ForegroundColor Green
104+
} else {
105+
Write-Host " ⚠ Dockerfile not found at $dockerfilePath, skipping region update..." -ForegroundColor Yellow
106+
}
107+
108+
# Step 5: Install CDK dependencies
109+
Write-Host "`n[5/11] Installing CDK dependencies..." -ForegroundColor Yellow
91110
Write-Host " (Installing AWS CDK libraries and TypeScript packages for infrastructure code)" -ForegroundColor Gray
92111
if (-not (Test-Path "cdk/node_modules")) {
93112
Push-Location cdk
@@ -97,8 +116,8 @@ if (-not (Test-Path "cdk/node_modules")) {
97116
Write-Host " CDK dependencies already installed, skipping..." -ForegroundColor Gray
98117
}
99118

100-
# Step 5: Install frontend dependencies
101-
Write-Host "`n[5/10] Installing frontend dependencies..." -ForegroundColor Yellow
119+
# Step 6: Install frontend dependencies
120+
Write-Host "`n[6/11] Installing frontend dependencies..." -ForegroundColor Yellow
102121
Write-Host " (Installing React, Vite, Cognito SDK, and UI component libraries)" -ForegroundColor Gray
103122
Push-Location frontend
104123
# Commented out to save time during development - uncomment for clean builds
@@ -111,7 +130,7 @@ Pop-Location
111130

112131
# Step 6: Create placeholder dist BEFORE any CDK commands
113132
# (CDK synthesizes all stacks even when deploying one, so frontend/dist must exist)
114-
Write-Host "`n[6/10] Creating placeholder frontend build..." -ForegroundColor Yellow
133+
Write-Host "`n[7/11] Creating placeholder frontend build..." -ForegroundColor Yellow
115134
Write-Host " (Generating temporary HTML file - required for CDK synthesis)" -ForegroundColor Gray
116135
if (-not (Test-Path "frontend/dist")) {
117136
New-Item -ItemType Directory -Path "frontend/dist" -Force | Out-Null
@@ -121,7 +140,7 @@ if (-not (Test-Path "frontend/dist")) {
121140
}
122141

123142
# Step 7: Bootstrap CDK (if needed)
124-
Write-Host "`n[7/10] Bootstrapping CDK environment..." -ForegroundColor Yellow
143+
Write-Host "`n[8/11] Bootstrapping CDK environment..." -ForegroundColor Yellow
125144
Write-Host " (Setting up CDK deployment resources in your AWS account/region)" -ForegroundColor Gray
126145
Push-Location cdk
127146
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
@@ -134,7 +153,7 @@ if ($LASTEXITCODE -ne 0) {
134153
}
135154

136155
# Step 8: Deploy infrastructure stack
137-
Write-Host "`n[8/10] Deploying infrastructure stack..." -ForegroundColor Yellow
156+
Write-Host "`n[9/11] Deploying infrastructure stack..." -ForegroundColor Yellow
138157
Write-Host " (Creating ECR repository, CodeBuild project, S3 bucket, and IAM roles)" -ForegroundColor Gray
139158
Push-Location cdk
140159
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
@@ -147,7 +166,7 @@ if ($LASTEXITCODE -ne 0) {
147166
}
148167

149168
# Step 9: Deploy auth stack
150-
Write-Host "`n[9/10] Deploying authentication stack..." -ForegroundColor Yellow
169+
Write-Host "`n[10/11] Deploying authentication stack..." -ForegroundColor Yellow
151170
Write-Host " (Creating Cognito User Pool with email verification and password policies)" -ForegroundColor Gray
152171
Push-Location cdk
153172
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
@@ -160,7 +179,7 @@ if ($LASTEXITCODE -ne 0) {
160179
}
161180

162181
# Step 10: Deploy backend stack (triggers build and waits via Lambda)
163-
Write-Host "`n[10/10] Deploying AgentCore backend stack..." -ForegroundColor Yellow
182+
Write-Host "`n[11/11] Deploying AgentCore backend stack..." -ForegroundColor Yellow
164183
Write-Host " (Uploading agent code, building ARM64 Docker image, creating AgentCore runtime with built-in Cognito auth)" -ForegroundColor Gray
165184
Write-Host " Note: CodeBuild will compile the container image - this takes 5-10 minutes" -ForegroundColor DarkGray
166185
Write-Host " The deployment will pause while waiting for the build to complete..." -ForegroundColor DarkGray

deploy-all.sh

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e # Exit on error
77
echo -e "\033[0;36m=== AgentCore Demo Deployment ===\033[0m"
88

99
# Step 1: Verify AWS credentials
10-
echo -e "\n\033[0;33m[1/10] Verifying AWS credentials...\033[0m"
10+
echo -e "\n\033[0;33m[1/11] Verifying AWS credentials...\033[0m"
1111
echo -e "\033[0;90m (Checking AWS CLI configuration and validating access)\033[0m"
1212

1313
# Check if AWS credentials are configured
@@ -28,7 +28,7 @@ echo -e "\033[0;32m Authenticated as: $ARN\033[0m"
2828
echo -e "\033[0;32m AWS Account: $ACCOUNT_ID\033[0m"
2929

3030
# Step 2: Check AWS CLI version
31-
echo -e "\n\033[0;33m[2/10] Checking AWS CLI version...\033[0m"
31+
echo -e "\n\033[0;33m[2/11] Checking AWS CLI version...\033[0m"
3232
AWS_VERSION=$(aws --version 2>&1)
3333
if [[ $AWS_VERSION =~ aws-cli/([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
3434
MAJOR=${BASH_REMATCH[1]}
@@ -56,7 +56,7 @@ else
5656
fi
5757

5858
# Step 3: Check AgentCore availability in current region
59-
echo -e "\n\033[0;33m[3/10] Checking AgentCore availability in current region...\033[0m"
59+
echo -e "\n\033[0;33m[3/11] Checking AgentCore availability in current region...\033[0m"
6060
# Detect current region from AWS CLI configuration
6161
CURRENT_REGION=$(aws configure get region)
6262
if [ -z "$CURRENT_REGION" ]; then
@@ -81,8 +81,26 @@ if ! aws bedrock-agentcore-control list-agent-runtimes --region "$CURRENT_REGION
8181
fi
8282
echo -e "\033[0;32m ✓ AgentCore is available in $CURRENT_REGION\033[0m"
8383

84-
# Step 4: Install CDK dependencies
85-
echo -e "\n\033[0;33m[4/10] Installing CDK dependencies...\033[0m"
84+
# Step 4: Update Dockerfile with current region
85+
echo -e "\n\033[0;33m[4/11] Updating Dockerfile with current region...\033[0m"
86+
echo -e "\033[0;90m (Setting AWS_REGION and AWS_DEFAULT_REGION to $CURRENT_REGION in agent/Dockerfile)\033[0m"
87+
88+
DOCKERFILE_PATH="agent/Dockerfile"
89+
if [ -f "$DOCKERFILE_PATH" ]; then
90+
# Replace both AWS_REGION and AWS_DEFAULT_REGION with current region
91+
sed -i.bak -E "s/AWS_REGION=[a-zA-Z0-9-]+/AWS_REGION=$CURRENT_REGION/g" "$DOCKERFILE_PATH"
92+
sed -i.bak -E "s/AWS_DEFAULT_REGION=[a-zA-Z0-9-]+/AWS_DEFAULT_REGION=$CURRENT_REGION/g" "$DOCKERFILE_PATH"
93+
94+
# Remove backup file
95+
rm -f "$DOCKERFILE_PATH.bak"
96+
97+
echo -e "\033[0;32m ✓ Updated Dockerfile with region: $CURRENT_REGION\033[0m"
98+
else
99+
echo -e "\033[0;33m ⚠ Dockerfile not found at $DOCKERFILE_PATH, skipping region update...\033[0m"
100+
fi
101+
102+
# Step 5: Install CDK dependencies
103+
echo -e "\n\033[0;33m[5/11] Installing CDK dependencies...\033[0m"
86104
echo -e "\033[0;90m (Installing AWS CDK libraries and TypeScript packages for infrastructure code)\033[0m"
87105
if [ ! -d "cdk/node_modules" ]; then
88106
pushd cdk > /dev/null
@@ -92,8 +110,8 @@ else
92110
echo -e "\033[0;90m CDK dependencies already installed, skipping...\033[0m"
93111
fi
94112

95-
# Step 5: Install frontend dependencies
96-
echo -e "\n\033[0;33m[5/10] Installing frontend dependencies...\033[0m"
113+
# Step 6: Install frontend dependencies
114+
echo -e "\n\033[0;33m[6/11] Installing frontend dependencies...\033[0m"
97115
echo -e "\033[0;90m (Installing React, Vite, Cognito SDK, and UI component libraries)\033[0m"
98116
pushd frontend > /dev/null
99117
# Commented out to save time during development - uncomment for clean builds
@@ -106,7 +124,7 @@ popd > /dev/null
106124

107125
# Step 6: Create placeholder dist BEFORE any CDK commands
108126
# (CDK synthesizes all stacks even when deploying one, so frontend/dist must exist)
109-
echo -e "\n\033[0;33m[6/10] Creating placeholder frontend build...\033[0m"
127+
echo -e "\n\033[0;33m[7/11] Creating placeholder frontend build...\033[0m"
110128
echo -e "\033[0;90m (Generating temporary HTML file - required for CDK synthesis)\033[0m"
111129
if [ ! -d "frontend/dist" ]; then
112130
mkdir -p frontend/dist
@@ -116,31 +134,31 @@ else
116134
fi
117135

118136
# Step 7: Bootstrap CDK (if needed)
119-
echo -e "\n\033[0;33m[7/10] Bootstrapping CDK environment...\033[0m"
137+
echo -e "\n\033[0;33m[8/11] Bootstrapping CDK environment...\033[0m"
120138
echo -e "\033[0;90m (Setting up CDK deployment resources in your AWS account/region)\033[0m"
121139
pushd cdk > /dev/null
122140
TIMESTAMP=$(date +%Y%m%d%H%M%S)
123141
npx cdk bootstrap --output "cdk.out.$TIMESTAMP" --no-cli-pager
124142
popd > /dev/null
125143

126144
# Step 8: Deploy infrastructure stack
127-
echo -e "\n\033[0;33m[8/10] Deploying infrastructure stack...\033[0m"
145+
echo -e "\n\033[0;33m[9/11] Deploying infrastructure stack...\033[0m"
128146
echo -e "\033[0;90m (Creating ECR repository, CodeBuild project, S3 bucket, and IAM roles)\033[0m"
129147
pushd cdk > /dev/null
130148
TIMESTAMP=$(date +%Y%m%d%H%M%S)
131149
npx cdk deploy AgentCoreInfra --output "cdk.out.$TIMESTAMP" --no-cli-pager --require-approval never
132150
popd > /dev/null
133151

134152
# Step 9: Deploy auth stack
135-
echo -e "\n\033[0;33m[9/10] Deploying authentication stack...\033[0m"
153+
echo -e "\n\033[0;33m[10/11] Deploying authentication stack...\033[0m"
136154
echo -e "\033[0;90m (Creating Cognito User Pool with email verification and password policies)\033[0m"
137155
pushd cdk > /dev/null
138156
TIMESTAMP=$(date +%Y%m%d%H%M%S)
139157
npx cdk deploy AgentCoreAuth --output "cdk.out.$TIMESTAMP" --no-cli-pager --require-approval never
140158
popd > /dev/null
141159

142160
# Step 10: Deploy backend stack (triggers build and waits via Lambda)
143-
echo -e "\n\033[0;33m[10/10] Deploying AgentCore backend stack...\033[0m"
161+
echo -e "\n\033[0;33m[11/11] Deploying AgentCore backend stack...\033[0m"
144162
echo -e "\033[0;90m (Uploading agent code, building ARM64 Docker image, creating AgentCore runtime with built-in Cognito auth)\033[0m"
145163
echo -e "\033[0;90m Note: CodeBuild will compile the container image - this takes 5-10 minutes\033[0m"
146164
echo -e "\033[0;90m The deployment will pause while waiting for the build to complete...\033[0m"

0 commit comments

Comments
 (0)