Skip to content

agentcore: L2 constructs don't set node.defaultChild, breaking applyRemovalPolicy #38327

Description

@sanyamk23

I noticed this while fixing #38262, and I am posting it as a tracking issue because the problem is not isolated to Memory.

Most of the bedrockagentcore L2 constructs create their Cfn resource plus at least one other child (usually a ServiceRole). Because of that, CDK never auto-assigns the Cfn resource as node.defaultChild, and calling applyRemovalPolicy() on the L2 throws:

CannotApplyRemovalPolicy: Cannot apply RemovalPolicy: no child or not a CfnResource.

This affects the following constructs (from a quick scan of packages/aws-cdk-lib/aws-bedrockagentcore/lib):

  • tools/browser.ts
  • tools/code-interpreter.ts
  • memory/memory.ts (fixed in fix(bedrockagentcore): set default child on Memory L2 so applyRemovalPolicy works #38313)
  • identity/workload-identity.ts
  • identity/oauth2-credential-provider.ts
  • identity/api-key-credential-provider.ts
  • runtime/runtime.ts
  • runtime/runtime-endpoint.ts
  • evaluation/online-evaluation.ts
  • evaluation/custom-evaluator.ts
  • gateway/gateway.ts
  • gateway/targets/target.ts
  • observability.ts (creates several Cfn children)

The fix is the same one-liner in each case: assign this.node.defaultChild = this.__resource (or whatever the Cfn field is) right after constructing it, matching how s3.Bucket and dynamodb.Table do it.

I have done Memory in #38313. I am happy to work through the rest if that is okay, or anyone else can grab individual ones. I thought a single tracking issue was better than opening twelve separate ones.

Progress

I will work through the remaining ones as separate small PRs so each is easy to review.

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