Skip to content

fix(cli): In load-dev-env.ts, resolve the deployed target region fr... (#1457)#50

Draft
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1457
Draft

fix(cli): In load-dev-env.ts, resolve the deployed target region fr... (#1457)#50
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1457

Conversation

@aidandaly24

Copy link
Copy Markdown
Owner

Refs aws#1457

Issues

  • bug: agentcore dev fails on mismatched regions aws/agentcore-cli#1457 — When a user runs agentcore dev against an agent that uses AgentCore Memory, and their shell's AWS region (AWS_REGION/AWS_DEFAULT_REGION, or none set) differs from the region where the memory was actually deployed (per aws-targets.json), the local agent calls ListEvents in the wrong region and fails hard with ResourceNotFoundException ("Memory not found"). The deployed memory ID is injected correctly, but the region it lives in is not, so invocations break in a confusing way during local dev. Single-region users whose shell region matches the target are unaffected.

Root cause

CLI dev path injects deployed memory ID but never the deployed target region: load-dev-env.ts:21-32 merges gateway/memory/payment+.env only (no region logic, no region-env.ts); codezip-dev-server.ts:138 builds subprocess env as {...process.env, ...envVars, PORT, LOCAL_DEV}; vended asset session.py:9 reads REGION=os.getenv('AWS_REGION'). applyTargetRegionToEnv (target-region.ts:23, fix for aws#924) is wired only into deploy/actions.ts:171, teardown.ts:73, useCdkPreflight.ts:410 — never the dev command. Container path (container-dev-server.ts:182-195) forwards region only from process.env, same gap. SDK is correct (session_manager.py:146-147 uses the region it's given, defaulting to boto3 chain when None).

The fix

In load-dev-env.ts resolve the target region from aws-targets.json (same read as browser-mode.ts:43-53) and add AWS_REGION/AWS_DEFAULT_REGION to returned envVars before the .env spread (deployed target authoritative, user .env can still override). Single injection point covers CodeZip (codezip-dev-server.ts:138) and Container (container-dev-server.ts:216/224-230) and all entry points (command.tsx:388, useDevServer.ts:114, browser-mode.ts:162/242). No SDK/asset change. Multi-target: pick the same target the dev path already uses (targets[0]). Add a unit test.

Files touched: src/cli/operations/dev/load-dev-env.ts (primary; optionally a new src/cli/operations/dev/region-env.ts). Reuse aws-targets read from src/cli/commands/dev/browser-mode.ts:43-53 and the AWS_REGION helper concept in src/cli/aws/target-region.ts:23.

Validation evidence

The fix was verified by reproducing the original symptom and re-running after the change:

BEFORE (fix stashed; pre-fix load-dev-env.ts merges only {...gatewayEnvVars, ...memoryEnvVars, ...paymentEnvVars, ...dotEnvVars} with no region injection): the issue-aws#1457 unit test FAILS — expect(envVars.AWS_REGION).toBe('us-west-2') → AssertionError "expected undefined to be 'us-west-2'", even though deployedState's first target maps to region us-west-2 in aws-targets.json and the shell has process.env.AWS_REGION=us-east-1. This is the exact symptom: deployed target region is never injected, SDK falls back to the shell/boto3 region, ListEvents hits the wrong region. (The .env-override and absent-targets tests trivially pass pre-fix because no region var is added at all.) AFTER (fix restored): load-dev-env.ts now spreads ...regionEnvVars FIRST via new getRegionEnvVars() from region-env.ts; all 3 tests pass — AWS_REGION/AWS_DEFAULT_REGION=us-west-2 injected despite shell us-east-1; explicit .env AWS_REGION=eu-west-1 still overrides (region spread before dotEnv spread); absent/unreadable aws-targets.json omits region vars and does not throw. region-env.ts sources region identically to browser-mode.ts:43-53 (awsTargets.find(t=>t.name===targetName).region on the first deployed target, try/catch -> {}). Build: OK dist/cli/index.mjs (exit 0).

Test suite: green.


Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.

…ntcore dev env

Resolve the deployed target region from aws-targets.json and inject
AWS_REGION/AWS_DEFAULT_REGION into the dev subprocess env before the
.env spread, so local dev against AgentCore Memory calls ListEvents in
the region where the memory was actually deployed instead of falling
back to the shell/boto3 region. Fixes aws#1457.
@github-actions github-actions Bot added the size/m PR size: M label Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 37.19% 13610 / 36588
🔵 Statements 36.46% 14470 / 39681
🔵 Functions 31.83% 2336 / 7338
🔵 Branches 31.12% 9006 / 28938
Generated in workflow #104 for commit 782b899 by the Vitest Coverage Report Action

@github-actions github-actions Bot added agentcore-harness-reviewing AgentCore Harness review in progress and removed agentcore-harness-reviewing AgentCore Harness review in progress labels Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant