-
Notifications
You must be signed in to change notification settings - Fork 4.5k
aws-cdk-lib(core): App Inherits From Stage, But Doesn't Allow Setting Region #24570
Description
Describe the bug
I believe there's a fundamental "miss" in the code for App. App inherits from Stage yet does not allow setting any of the StageProps. As defined here
aws-cdk/packages/@aws-cdk/core/lib/stage.ts
Lines 13 to 43 in 15cb919
| /** | |
| * Default AWS environment (account/region) for `Stack`s in this `Stage`. | |
| * | |
| * Stacks defined inside this `Stage` with either `region` or `account` missing | |
| * from its env will use the corresponding field given here. | |
| * | |
| * If either `region` or `account`is is not configured for `Stack` (either on | |
| * the `Stack` itself or on the containing `Stage`), the Stack will be | |
| * *environment-agnostic*. | |
| * | |
| * Environment-agnostic stacks can be deployed to any environment, may not be | |
| * able to take advantage of all features of the CDK. For example, they will | |
| * not be able to use environmental context lookups, will not automatically | |
| * translate Service Principals to the right format based on the environment's | |
| * AWS partition, and other such enhancements. | |
| * | |
| * @example | |
| * | |
| * // Use a concrete account and region to deploy this Stage to | |
| * new Stage(app, 'Stage1', { | |
| * env: { account: '123456789012', region: 'us-east-1' }, | |
| * }); | |
| * | |
| * // Use the CLI's current credentials to determine the target environment | |
| * new Stage(app, 'Stage2', { | |
| * env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION }, | |
| * }); | |
| * | |
| * @default - The environments should be configured on the `Stack`s. | |
| */ | |
| readonly env?: Environment; |
env allows setting the region from which all other resources in the stage will use.
Even when casting as any to force env into Apps constructor, App ignores props as a whole and only passes outdir as can be seen here:
aws-cdk/packages/@aws-cdk/core/lib/app.ts
Lines 160 to 162 in 15cb919
| super(undefined as any, '', { | |
| outdir: props.outdir ?? process.env[cxapi.OUTDIR_ENV], | |
| }); |
Also of note, not passing a region to a Stack constructor's props will default the stack to us-east-1 even though --verbose output shows that CDK_DEFAULT_REGION has been correctly pulled from ~/.aws/config.
Expected Behavior
I would expect a number of things here:
- We can set the region for the entire stage, via
AppinAppProps - The stage and stacks within it would use the value present in
CDK_DEFAULT_REGIONif nothing was specified manually in props - There would be a warning that
CDK_DEFAULT_REGIONdiverged from what the default value ofus-east-1with instructions or hints as to how to proceed.
Current Behavior
The stage silently defaults to us-east-1
Reproduction Steps
Please reference code permalinks above
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.68.0
Framework Version
2.68.0
Node.js Version
18
OS
Mac Vetura
Language
Typescript
Language Version
4.9
Other information
No response