Skip to content

fix(payments): self-heal empty aws-targets.json before T02 deploy#1672

Closed
fahadfa-aws wants to merge 1 commit into
awslabs:mainfrom
fahadfa-aws:fix/payments-t02-self-heal-aws-targets
Closed

fix(payments): self-heal empty aws-targets.json before T02 deploy#1672
fahadfa-aws wants to merge 1 commit into
awslabs:mainfrom
fahadfa-aws:fix/payments-t02-self-heal-aws-targets

Conversation

@fahadfa-aws

@fahadfa-aws fahadfa-aws commented Jun 13, 2026

Copy link
Copy Markdown

Issue

The @aws/agentcore CLI scaffolds <project>/agentcore/aws-targets.json as an empty list. agentcore deploy then exits with Target "default" not found in aws-targets.json before the CDK synth runs, and the user sees a confusing error with no clear next step.

Live-reproduced today on both 0.14.0 and 0.19.0 (current latest). The scaffold writes [] regardless of CLI version, so a fresh user following Tutorial 02 cannot deploy without intervention.

A version pin in the README would not help here — the behavior is consistent across the versions a fresh user is likely to install. This PR uses a property-based check instead: if the file exists but doesn't contain a default target, append one using the account/region the script has already resolved.

Changes

deploy_payment_agent.py: between scaffolding (agentcore create) and deploy (agentcore deploy), check aws-targets.json and append a default entry if missing. Existing entries are preserved. Malformed JSON, unexpected shapes (top-level dict, garbage list entries), and missing files are all left alone so the user sees the underlying CLI error rather than a silent overwrite.

README.md: troubleshooting entry covering the symptom and a one-line manual fix for users running agentcore deploy directly without the script.

Verification

Static — tested the probe in isolation against 8 input shapes:

Input shape Action
[] (the actual scaffold output) Append default
File missing Pass through
[{name: default, ...}] No-op
Malformed JSON Pass through
Whitespace-only Pass through (treated as malformed)
[{name: prod, ...}] Append default, preserve prod
Garbage list [1, 2, "x"] Pass through
Top-level dict {...} instead of list Pass through

All 8 pass. The inserted code in deploy_payment_agent.py is byte-equivalent to the standalone-tested function.

Live AWS — ran end-to-end against us-west-2 on both CLI versions:

CLI version Scaffold output Without probe With probe
0.14.0 [] Fails: Target "default" not found in aws-targets.json CFN stack AgentCore-PaymentAgent-default reaches CREATE_COMPLETE
0.19.0 [] Same failure Same success

Both stacks were torn down after validation. Variables account_id (line 51) and REGION (line 52) are already in scope at the insertion point. json and os are already imported. The probe is positioned after the existing if not os.path.exists(project_dir) skip so the directory is guaranteed to exist.

Some agentcore CLI versions scaffold <project>/agentcore/aws-targets.json
as an empty list, which makes `agentcore deploy` exit with
`Target "default" not found in aws-targets.json` before the CDK synth.

Detect that shape in deploy_payment_agent.py and append a `default`
target with the account/region the script already resolved. Other
entries are preserved, malformed or unexpected shapes are skipped so
the user sees the underlying CLI error instead of a silent overwrite.

This trades a CLI-version pin in the README (which would go stale the
next time @aws/agentcore ships a new version) for a property-based
check that keeps working across versions: as long as the failure shape
is "no default target in the list", the script self-heals.

- deploy_payment_agent.py: add the probe between scaffold and deploy.
- README.md: troubleshooting entry covering the symptom and the
  manual fix for users running `agentcore deploy` directly.
@fahadfa-aws

Copy link
Copy Markdown
Author

@mvangara10 — flagging this for your review when you have a moment. Tagged across the full set of payments-tutorial fixes I've been pushing today; happy to walk through any of them. Audit logs and test evidence are referenced in the PR description.

@fahadfa-aws

Copy link
Copy Markdown
Author

Superseded by #1738 (consolidated PR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant