aws-samples / aws-samples/agents4energy
AgentCore Gateway CDK construct: CloudFormation export name collides across stacks/sandboxes
- Dominant language
- TypeScript
- Stars
- 48
- Forks
- 68
- PR merge metrics
- No merged PRs in 30d
Description
The AgentCore Gateway CDK construct (used in `web/amplify/constructs/agentCoreApplication.ts`) exports a CloudFormation output with a fixed logical name (of the form `Gateway--Url`, e.g. `Gateway-default-gateway-Url`), rather than one scoped/uniqued per stack. Deploying a second sandbox stack that also creates a gateway with the same name (e.g. `default-gateway`, from `agentcore.json`) fails at the CloudFormation layer with:
```
Export with name TokenTOKEN3753-Gateway-default-gateway-Url is already exported by stack amplify-web-main-sandbox-...
```
This means only one Amplify sandbox stack in an account/region can have a gateway named `default-gateway` deployed at a time — a second developer's sandbox, or a second branch's ephemeral stack, collides with an existing one.
### Where this was found
Discovered while trying to stand up an isolated sandbox deploy of PR #178 (`import/issue-66`) for verification, alongside the already-deployed `main` sandbox stack (`amplify-web-main-sandbox-949a6d20d0`). The new stack's CDK/CloudFormation deploy failed with the export-name collision above. This is not caused by that PR (it only changes frontend code) — it's a pre-existing bug in the shared AgentCore CDK construct that surfaces whenever two stacks in the same account/region both provision a gateway of the same name.
### Suggested fix
Scope the CloudFormation export name to the stack (e.g. include `Stack.of(this).stackName` or the construct's unique node path in the export name), or avoid a fixed-name `CfnOutput`/export altogether and pass the gateway URL between stacks via a different mechanism (e.g. nested stack parameter, SSM parameter scoped per stack, or just referencing the token directly if consumer and producer are in the same stack).
Contributor guide
Research direction
Start by reading web/amplify/constructs/agentCoreApplication.ts and trace how the AgentCore Gateway CfnOutput export name is assembled from the gateway name and stack context. Confirm the behavior with two sandbox stacks using the same default-gateway name; done means both stacks deploy in the same account and region without an export-name collision.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100