Skip to content

(aws-bedrock-agentcore-alpha): Construct ID Collision When Binding Multiple OpenAPI Schemas to Gateway #36559

@ian-norris-ncino

Description

@ian-norris-ncino

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.

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

  1. Create two OpenAPI schema files (e.g., schema1.json, schema2.json)
  2. 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);
  1. Run cdk synth or cdk deploy
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions