From dd2bc560bd45bb79c962e2f95fae4f5d1da6f2e5 Mon Sep 17 00:00:00 2001 From: Fahad Farrukh Date: Fri, 12 Jun 2026 22:56:23 -0400 Subject: [PATCH] fix(payments): self-heal empty aws-targets.json before T02 deploy Some agentcore CLI versions scaffold /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. --- .../02-deploy-to-agentcore-runtime/README.md | 7 +++++++ .../deploy_payment_agent.py | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/01-features/08-agents-that-transact/00-getting-started/02-deploy-to-agentcore-runtime/README.md b/01-features/08-agents-that-transact/00-getting-started/02-deploy-to-agentcore-runtime/README.md index 2f65409e9..a546fcdae 100644 --- a/01-features/08-agents-that-transact/00-getting-started/02-deploy-to-agentcore-runtime/README.md +++ b/01-features/08-agents-that-transact/00-getting-started/02-deploy-to-agentcore-runtime/README.md @@ -138,6 +138,13 @@ npm install -g @aws/agentcore agentcore --version ``` +### agentcore deploy fails with `Target "default" not found in aws-targets.json` + +Some agentcore CLI versions scaffold `/agentcore/aws-targets.json` as an empty list, which makes `agentcore deploy` exit before the CDK synth. The `deploy_payment_agent.py` script appends a `default` entry automatically when it sees this. If you ran `agentcore deploy` directly, write the file by hand and re-run: +```bash +echo '[{"name":"default","account":"","region":""}]' > PaymentAgent/agentcore/aws-targets.json +``` + ### Deploy fails with CDK bootstrap error Bootstrap CDK in your account/region first: diff --git a/01-features/08-agents-that-transact/00-getting-started/02-deploy-to-agentcore-runtime/deploy_payment_agent.py b/01-features/08-agents-that-transact/00-getting-started/02-deploy-to-agentcore-runtime/deploy_payment_agent.py index 5ac498534..0215d773a 100644 --- a/01-features/08-agents-that-transact/00-getting-started/02-deploy-to-agentcore-runtime/deploy_payment_agent.py +++ b/01-features/08-agents-that-transact/00-getting-started/02-deploy-to-agentcore-runtime/deploy_payment_agent.py @@ -146,6 +146,27 @@ print("pyproject.toml updated") +# Some agentcore CLI versions scaffold aws-targets.json as an empty list, +# which causes `agentcore deploy` to exit with `Target "default" not found +# in aws-targets.json`. Append a default target if one is missing, and leave +# any other entries alone. +targets_file = os.path.join(project_dir, "agentcore", "aws-targets.json") +if os.path.exists(targets_file): + try: + with open(targets_file) as f: + targets = json.loads(f.read() or "[]") + except json.JSONDecodeError: + targets = None + if ( + isinstance(targets, list) + and all(isinstance(t, dict) and "name" in t for t in targets) + and not any(t["name"] == "default" for t in targets) + ): + targets.append({"name": "default", "account": account_id, "region": REGION}) + with open(targets_file, "w") as f: + f.write(json.dumps(targets, indent=2)) + print(f"Added default target to aws-targets.json (account={account_id}, region={REGION})") + # ── Step 7: Deploy to AgentCore Runtime ─────────────────────────────────────── print("\n── Step 7: Deploy to AgentCore Runtime ──") print("This creates billable AWS resources (Lambda, CloudWatch, API Gateway).")