-
Notifications
You must be signed in to change notification settings - Fork 264
Description
Description
In version 2.96.0, the ConstructsFeatureFlagsReport.ensure() method uses App.of(scope) to find the root App. However, when Solutions Constructs are used within CDK Pipelines (specifically when constructs are instantiated in a Stage within a Pipeline), App.of() returns the Stage object instead of the root App, causing a validation error.
Code Reference
The issue originates from this line in constructs-feature-flags.ts:
Line 31 in f24ff08
| const app = App.of(scope); |
public static ensure(scope: Construct) {
const app = App.of(scope); // Returns Stage in CDK Pipelines context
if (!app) {
throw new Error('Invalid scope provided to ConstructsFeatureFlagsReport');
}
const id = 'AwsSolutionsFeatureFlagsReport';
if (!app.node.tryFindChild(id)) {
new ConstructsFeatureFlagsReport(app, id);
}
}Error Message
ValidationError: ConstructsFeatureFlagsReport at 'HubPipeline/HubTest-EuWest1/AwsSolutionsFeatureFlagsReport'
should be created in the scope of a Stack, but no Stack found
at path [HubPipeline/HubTest-EuWest1] in aws-cdk-lib.Stage
Architecture
App (root)
└── CdkPipeline (Stack)
└── TestStage-EuWest1 (Stage) ← App.of() returns this Stage
└── AppStack (Stack)
└── AppConstruct (Construct)
└── SnsToSqs (Solutions Construct)
When SnsToSqs calls ConstructsFeatureFlagsReport.ensure(this), the App.of(scope) traverses up the tree and stops at the first App instance it finds. However, in CDK Pipelines, the Stage class extends App (via composition), so App.of() returns the Stage instead of the root App.
Reproduction Steps
- Create a CDK Pipeline with a Stage
- Within the Stage, create a Stack
- Within the Stack, use any Solutions Construct that instantiates
SnsToSqsinside aConstruct(not directly in aStack) - Run
cdk synthorcdk list
Expected Behavior
ConstructsFeatureFlagsReport should be created at the root App level, regardless of whether the construct is used within a CDK Pipeline Stage.
Actual Behavior
ConstructsFeatureFlagsReport is created at the Stage level, which causes a validation error because it's not in a Stack scope.
Environment
- AWS CDK: 2.231.0
- AWS Solutions Constructs: 2.96.0
- Node.js: 22.13.1
- TypeScript: 5.7.3
Workaround
Downgrade to AWS Solutions Constructs v2.92.0 or earlier, which doesn't include the ConstructsFeatureFlagsReport feature.
Additional Context
This issue was introduced in v2.93.0 when feature flag infrastructure was added (#1407). The feature appears to have been tested only with simple App → Stack hierarchies, not with CDK Pipelines that use Stages.
CDK Pipelines are a common pattern for multi-environment deployments, so this issue affects many production use cases.