fix(deploy): auto-populate default target on non-interactive deploy#1478
Conversation
A freshly-created project has an empty aws-targets.json by design (both interactive and non-interactive create write []; the target is populated at deploy time). The interactive deploy flow prompts for the target via the TUI, but the non-interactive path (deploy --yes/--json/--target) routes through handleDeploy, which looked up the 'default' target and failed with 'Target "default" not found' on any fresh project. Only 'agentcore dev' (runCliDeploy) auto-populated the target from the detected AWS context; plain non-interactive deploy did not. Extract that logic into a shared ensureDefaultDeploymentTarget helper and call it in handleDeploy before the target lookup, so all non-interactive deploys detect the account/region and write a single 'default' target (best-effort; if the account can't be detected the existing clear error still surfaces). runCliDeploy reuses the same helper. Addresses the deploy half of aws#699. Tests: unit (ensure-target.test.ts) + integ (deploy-autopopulate-target.test.ts); manually verified via npm run bundle + global install + create/deploy.
|
Claude Security Review: no high-confidence findings. (run) |
Package TarballHow to installgh release download pr-1478-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-0.18.0.tgz |
agentcore-cli-automation
left a comment
There was a problem hiding this comment.
Thanks for the fix — the shared helper and the two-call sites cleanup look good. One concern with the new integ test that should be addressed before merging.
- useDevDeploy (dev TUI path) now uses ensureDefaultDeploymentTarget instead of its own duplicated inline auto-populate block, so all deploy entry points (handleDeploy, runCliDeploy, dev TUI) go through one helper. - Remove integ-tests/deploy-autopopulate-target.test.ts: per integ-tests/README.md integ tests run without AWS credentials, where the auto-populate is a no-op and the middle assertion would fail. The unit tests in ensure-target.test.ts already cover the empty/populated/no-account branches.
|
Thanks for the review. Addressed both points:
Both in |
|
Claude Security Review: no high-confidence findings. (run) |
Hweinstock
left a comment
There was a problem hiding this comment.
Great win! This always bugged me.
| try { | ||
| targets = await configIO.readAWSDeploymentTargets(); | ||
| } catch { | ||
| // aws-targets.json missing or unreadable — treat as empty and try to populate. |
There was a problem hiding this comment.
q: this behavior is likely reasonable if we don't think customers are manually editing it (which I think I agree with). However, still wondering if we might want to surface the read error instead of silently overwrite the file?
There was a problem hiding this comment.
Good call — updated in 0a64ed8. It now only treats a genuinely-missing file (ConfigNotFoundError) as empty; any other read failure (corrupt JSON, validation, permissions) is rethrown so we don't silently overwrite a file that exists but couldn't be parsed. Added a unit test for the rethrow path.
| targets = await configIO.readAWSDeploymentTargets(); | ||
| } catch { | ||
| // aws-targets.json missing or unreadable — treat as empty and try to populate. | ||
| targets = []; |
There was a problem hiding this comment.
nit: can we just return false here?
There was a problem hiding this comment.
Done in 0a64ed8 — the catch now rethrows non-ConfigNotFoundError errors and only falls through to targets = [] for the missing-file case, so the structure is cleaner.
| type OnlineEvalEnableResult, | ||
| } from './post-deploy-online-evals'; | ||
|
|
||
| // Auto-populate a default deployment target for non-interactive deploys |
Per review feedback on aws#1478: - ensureDefaultDeploymentTarget now only treats a genuinely missing file (ConfigNotFoundError) as empty; any other read failure (corrupt JSON, validation, permissions) is rethrown instead of silently overwriting a file that exists but couldn't be parsed. - Drop the redundant export comment in operations/deploy/index.ts. - Add a unit test covering the rethrow path.
|
Claude Security Review: no high-confidence findings. (run) |
Problem
agentcore deployon a freshly-created project fails in non-interactive mode with:agentcore create(both interactive and non-interactive) writes an emptyaws-targets.jsonby design — the target is meant to be populated at deploy time. The interactive deploy flow prompts the user for the target (region/account) via the TUI. But the non-interactive path (deploy --yes/--json/--target) routes throughhandleDeploy, which just looks up the'default'target and errors when the array is empty.Notably,
agentcore dev(runCliDeploy) already auto-populated the target from the detected AWS context — but plain non-interactivedeploydid not, so the two diverged.Fix
Extract the auto-populate logic into a shared
ensureDefaultDeploymentTarget(configIO)helper and call it inhandleDeploybefore the target lookup. On an emptyaws-targets.json, it detects the account/region via the existingdetectAwsContext()and writes a singledefaulttarget. Best-effort: if the account can't be detected, nothing is written and the existing clear "target not found" error still surfaces.runCliDeploy(used bydev) now reuses the same helper instead of its own inline copy, removing duplication.Testing
src/cli/operations/deploy/__tests__/ensure-target.test.ts): empty → writes default; existing target → no-op; missing/unreadable file → populates; account undetectable → no write; detected region propagated.integ-tests/deploy-autopopulate-target.test.ts):createleaves[];deploy --json --dry-runno longer errors "not found"; with AWS creds,aws-targets.jsonis populated with adefaulttarget.npm run bundle→ installed the tarball globally →agentcore create --name X --no-agent(targets[]) →agentcore deploy --json --dry-run→aws-targets.jsonbecame[{name:"default", account, region}]and deploy advanced past target resolution (failed later only on the expected "No resources defined" for a--no-agentproject).Addresses #699