aws / aws/aws-cdk

(core): Cyclic dependencies during prepareApp()

Open
#29,501 7 comments 2 reactions 1 assignee Claimed by @dgandhi62 View on GitHub
@aws-cdk/core bug effort/medium p1
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

In certain scenarios, the prepareApp() phase generates cyclic dependencies while trying to find transitive dependencies of nested resources.

### Expected Behavior

DependsOn is not generated on resources that really don't need it.

### Current Behavior

Cyclic dependencies are generated by adding unnecessary DependsOn properties to resources.

### Reproduction Steps

https://github.com/FlorinAsavoaie/cdk-grant-bug

I wrote a very simple piece of code here and a test for it. You will notice that the Queue starts depending on the TaskRole Policy and there are no reasons why that should be happening.

### Additional Information/Context

I tried debugging this as much as possible. During synthesis, DependsOn on the CfnQueue resource node is empty until it reaches the prepareApp(root) step. Something goes wrong in the logic here.

If you search `prepareApp` in the list of issues on the project, most of the issues are referring to Cyclic Dependencies. I wouldn't be surprised if most of them are unnecessary, like reported here.

### CDK CLI Version

2.132.1 (build 9df7dd3)

### Node.js Version

v20.11.1

### OS

Linux, Windows

### Language

TypeScript, Java

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.