(bedrockagentcore): Policy fails with an engine from PolicyEngine.fromPolicyEngineAttributes

Open Beginner friendly
#39,690 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
aws, typescript

Research direction

Find the Policy constructor and inspect the unconditional addDependency call on this.policyEngine.node.defaultChild. Compare how PolicyEngine.fromPolicyEngineAttributes represents imported engines, then check nearby tests for policies using imported engines. Done means the reproduction synthesizes without throwing while dependency handling for non-imported engines still works.

Written by the indexing model from the issue text.

Description

@aws-cdk/aws-iam needs-triage
Describe the bug

Policy fails at synth when its policyEngine comes from PolicyEngine.fromPolicyEngineAttributes. The constructor calls addDependency(this.policyEngine.node.defaultChild) unconditionally, and an imported engine has no default child.

Regression Issue
  • Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version

No response

Expected Behavior

A policy can be added to an imported policy engine, e.g. one owned by another stack.

Current Behavior
TypeError: Cannot read properties of undefined (reading 'Symbol(@aws-cdk/core.DependableTrait)')
Reproduction Steps
const engine = agentcore.PolicyEngine.fromPolicyEngineAttributes(stack, 'Engine', {
  policyEngineArn: 'arn:aws:bedrock-agentcore:us-east-1:123456789012:policy-engine/example-abc123',
});
new agentcore.Policy(stack, 'Policy', {
  policyEngine: engine,
  policyName: 'example',
  statement: agentcore.PolicyStatement.fromCedar('permit(principal, action, resource);'),
});
Possible Solution

Only add the dependency when the engine has a default child. Workaround today: add an empty child named Default to the imported engine. Possibly related: #38327.

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

2.276.0

AWS CDK CLI version

n/a

Node.js Version

24

OS

n/a

Language

TypeScript

Language Version

No response

Other information

No response

Dominant language
TypeScript
Stars
13k
Forks
4.7k
Avg merge
4d 3h
Merged PRs (30d)
98

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aws/aws-cdk

All issues in aws/aws-cdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.