fix: prefix HTTP gateway names with project name to prevent cross-project collisions#1105
Conversation
…ject collisions
Previously, HTTP gateways were deployed to AWS using their raw name (e.g.
"my-api") instead of a project-prefixed name (e.g. "myproject-my-api").
This caused cross-project resource collisions when multiple projects used
the same gateway name in the same AWS account/region.
Changes:
- post-deploy-http-gateways.ts: prefix gateway name and all target names
with "${projectName}-" at deploy time
- http-gateway.ts: reduce max gateway name length from 48 to 24 chars so
the combined "{project}-{name}" string fits the 48-char AWS limit
- preflight.ts: add validateHttpGatewayNames() preflight check that
validates the combined name length before deployment begins
- Test files updated to reflect new prefixed names and 24-char boundary
- package.json: add NODE_OPTIONS=--experimental-require-module to all
test scripts to fix vitest ESM compatibility issue
BREAKING CHANGE: gateway names in agentcore.json are now limited to 24
characters (down from 48). Projects with longer gateway names must shorten
them before deploying.
Issue: Target name prefixing breaks target-based A/B tests
const controlTarget = `${options.runtime}-${options.controlEndpoint}`;
const treatmentTarget = `${options.runtime}-${options.treatmentEndpoint}`;
// ...
target: { targetName: controlTarget },
...(v.variantConfiguration.target && { target: { name: v.variantConfiguration.target.targetName } }),But after this PR, the actual target on AWS is created with name Why do target names need the prefix at all? Gateway names are globally unique within an account+region, which justifies prefixing them to avoid cross-project collisions. But gateway target names are scoped within a gateway — they can't collide across projects because the gateways themselves are already distinct. The stated root cause of this PR (cross-project name collisions) only applies to gateways. Options to fix:
|
Coverage Report
|
Issue: Existing-target lookup mismatch causes re-deploy to always re-attempt target creationIn for (const t of existingTargets.targets) {
existingTargetsByName.set(t.name, { targetId: t.targetId }); // key = actual AWS name (prefixed)
}
for (const tgt of gwSpec.targets) {
const existingTarget = existingTargetsByName.get(tgt.name); // lookup = unprefixed spec name
// ...
}After this PR, targets are created on AWS with name
Fix: Either look up by the same prefixed name we used to create ( Note: there's no test exercising this |
Issue: Migration path for existing deployments silently creates duplicate gatewaysThe PR description notes that old gateways "will not be automatically renamed" and customers "need to redeploy." But the state-loss recovery path in const prefixedGatewayName = `${projectName}-${gwSpec.name}`;
const existingByName = await findHttpGatewayByName(region, prefixedGatewayName);For a user who upgrades and loses local state (e.g., clean checkout, CI runner without persisted
Options:
|
Issue: Unrelated
|
Target-based AB tests were silently failing because resolveVariants() passed
the raw target name (e.g. "runtime-endpoint") to the AWS routing API, while
post-deploy-http-gateways.ts creates targets on AWS with a "${projectName}-"
prefix (e.g. "myproject-runtime-endpoint"). Fix resolveVariants() to prepend
projectName to the target name so it matches the deployed AWS resource.
Also fix the existingTargetsByName lookup in setupHttpGateways to key on the
prefixed name, ensuring idempotent target creation works correctly.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…(Comment 3) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
Addressed in commit The root cause was that You raised a valid design point about whether target names need prefixing at all since they're scoped within a gateway. The current approach (Option 2 from your list) was chosen to keep naming consistent: gateway names are prefixed, so target names follow the same |
|
Addressed in commit The lookup mismatch was exactly as you described — You're right that there was no test covering the |
|
Addressed in commits The fix adds a two-step fallback in the state-loss recovery path:
This avoids silently creating a duplicate gateway. The orphaned old gateway concern is still valid for users who do have state — they'll need a manual |
|
This comment is now stale — the |
Verification summarySmoke-tested the branch end-to-end before requesting review: Build
CLI commands
TUI flow
PR fix verification (bundle inspection)
Unit tests
|
…ht length validation Removes the redundant .max(24) cap from HttpGatewayNameSchema (the combined 48-char limit is enforced by validateHttpGatewayNames() in preflight.ts). Adds preflight validation for gateway targets so that projectName-targetName combinations exceeding the 48-char AWS limit are caught before deploy. Updates unit tests to match the new schema behaviour and cover the new target-length preflight check.
Root Cause
HTTP gateways were being deployed without a project-scoped prefix, causing cross-project name collisions when multiple projects shared the same AWS account or region. Gateway names were globally unique identifiers but were derived only from the gateway's local config, not the project context.
What Changed
6 files updated to prefix gateway names with the project name:
<project-name>-to all HTTP gateway namesCustomer Impact
Breaking change: Gateway names are now limited to 24 characters (to accommodate the project name prefix within AWS name length limits). Customers with existing gateways deployed under the old naming scheme will need to redeploy — old gateways will not be automatically renamed.
Test Results