Skip to content

aws-cdk-lib(core): App Inherits From Stage, But Doesn't Allow Setting Region #24570

@shellscape

Description

@shellscape

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

/**
* 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:

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:

  1. We can set the region for the entire stage, via App in AppProps
  2. The stage and stacks within it would use the value present in CDK_DEFAULT_REGION if nothing was specified manually in props
  3. There would be a warning that CDK_DEFAULT_REGION diverged from what the default value of us-east-1 with 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/coreRelated to core CDK functionalityeffort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.needs-discussionThis issue/PR requires more discussion with community.p1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions