fix(cli): In load-dev-env.ts, resolve the deployed target region fr... (#1457)#50
Draft
aidandaly24 wants to merge 1 commit into
Draft
fix(cli): In load-dev-env.ts, resolve the deployed target region fr... (#1457)#50aidandaly24 wants to merge 1 commit into
aidandaly24 wants to merge 1 commit into
Conversation
…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.
Coverage Report
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs aws#1457
Issues
agentcore devagainst 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:
Test suite: green.
Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.