-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Describe the bug
When using ApiSchema.fromLocalAsset().bind() multiple times in the same CDK construct scope, it creates multiple constructs with the same ID ('Schema'), causing a collision error.
aws-cdk/packages/@aws-cdk/aws-bedrock-agentcore-alpha/lib/gateway/targets/schema/api-schema.ts
Lines 116 to 127 in 40a7689
| public bind(scope: Construct): void { | |
| // If the same AssetApiSchema is used multiple times, retain only the first instantiation | |
| if (!this.asset) { | |
| // Note: Validation is handled at the target configuration level where we know the schema type | |
| // and whether validation is enabled | |
| this.asset = new s3_assets.Asset(scope, 'Schema', { | |
| path: this.path, | |
| ...this.options, | |
| }); | |
| // Note: Permissions will be granted by the Gateway target construct when adding the target | |
| } | |
| } |
Example:
// This causes a collision
const schema1 = ApiSchema.fromLocalAsset('path/to/schema1.json').bind(this);
const schema2 = ApiSchema.fromLocalAsset('path/to/schema2.json').bind(this); // Error: Construct with id 'Schema' already exists
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
Each bind() call should generate unique construct IDs automatically, or allow specifying custom IDs to avoid collisions when binding multiple schemas in the same scope.
Current Behavior
When binding multiple OpenAPI schemas in the same CDK construct scope, all schemas create a child construct with the same ID 'Schema', causing a collision error: Construct with id 'Schema' already exists in ApiStack
Reproduction Steps
- Create two OpenAPI schema files (e.g., schema1.json, schema2.json)
- In a CDK construct, bind both schemas:
const schema1 = ApiSchema.fromLocalAsset('path/to/schema1.json').bind(this);
const schema2 = ApiSchema.fromLocalAsset('path/to/schema2.json').bind(this);
- Run cdk synth or cdk deploy
- Error occurs on the second .bind() call
Possible Solution
No response
Additional Information/Context
No response
AWS CDK Library version (aws-cdk-lib)
2.233.0
AWS CDK CLI version
2.1100.1
Node.js Version
v22.16.0
OS
macOS Sequoia 15.7.3
Language
TypeScript
Language Version
5.9.3
Other information
No response