Skip to content

fix(deploy): auto-populate default target on non-interactive deploy#1478

Merged
jariy17 merged 3 commits into
aws:mainfrom
jariy17:fix/non-interactive-deploy-autopopulate-target
Jun 8, 2026
Merged

fix(deploy): auto-populate default target on non-interactive deploy#1478
jariy17 merged 3 commits into
aws:mainfrom
jariy17:fix/non-interactive-deploy-autopopulate-target

Conversation

@jariy17

@jariy17 jariy17 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Problem

agentcore deploy on a freshly-created project fails in non-interactive mode with:

Target "default" not found in aws-targets.json

agentcore create (both interactive and non-interactive) writes an empty aws-targets.json by 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 through handleDeploy, 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-interactive deploy did not, so the two diverged.

Fix

Extract the auto-populate logic into a shared ensureDefaultDeploymentTarget(configIO) helper and call it in handleDeploy before the target lookup. On an empty aws-targets.json, it detects the account/region via the existing detectAwsContext() and writes a single default target. Best-effort: if the account can't be detected, nothing is written and the existing clear "target not found" error still surfaces.

runCliDeploy (used by dev) now reuses the same helper instead of its own inline copy, removing duplication.

Testing

  • Unit (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 (integ-tests/deploy-autopopulate-target.test.ts): create leaves []; deploy --json --dry-run no longer errors "not found"; with AWS creds, aws-targets.json is populated with a default target.
  • Manual: npm run bundle → installed the tarball globally → agentcore create --name X --no-agent (targets []) → agentcore deploy --json --dry-runaws-targets.json became [{name:"default", account, region}] and deploy advanced past target resolution (failed later only on the expected "No resources defined" for a --no-agent project).

Addresses #699

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.
@jariy17 jariy17 requested a review from a team June 8, 2026 18:02
@github-actions github-actions Bot added the size/m PR size: M label Jun 8, 2026
@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 8, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Jun 8, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Jun 8, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Package Tarball

aws-agentcore-0.18.0.tgz

How to install

gh 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 agentcore-cli-automation left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread integ-tests/deploy-autopopulate-target.test.ts Outdated
@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 8, 2026
- 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.
@jariy17

jariy17 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed both points:

  • Integ test — removed deploy-autopopulate-target.test.ts entirely. You're right that it would fail in the no-credentials integ environment (auto-populate is a no-op → the middle assertion breaks). The unit tests in ensure-target.test.ts already cover the empty/populated/missing-file/no-account branches without needing creds.
  • Consistency — also updated useDevDeploy (the dev TUI path), which still had its own duplicated inline auto-populate block, to use the shared ensureDefaultDeploymentTarget helper. Now all deploy entry points (handleDeploy, runCliDeploy, and the dev TUI) go through the one function.

Both in 37d5a4b.

@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Jun 8, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Jun 8, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Jun 8, 2026
Hweinstock
Hweinstock previously approved these changes Jun 8, 2026

@Hweinstock Hweinstock left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we just return false here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/cli/operations/deploy/index.ts Outdated
type OnlineEvalEnableResult,
} from './post-deploy-online-evals';

// Auto-populate a default deployment target for non-interactive deploys

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unneeded comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 0a64ed8.

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.
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Jun 8, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Jun 8, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Jun 8, 2026
@jariy17 jariy17 merged commit 96be003 into aws:main Jun 8, 2026
29 checks passed
@jariy17 jariy17 deleted the fix/non-interactive-deploy-autopopulate-target branch June 8, 2026 20:12
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.

3 participants