Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shellscape opened this issue Mar 10, 2023 · 1 comment · May be fixed by #30050
Open

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

shellscape opened this issue Mar 10, 2023 · 1 comment · May be fixed by #30050
Labels
@aws-cdk/core Related to core CDK functionality aws-cdk-lib Related to the aws-cdk-lib package effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. needs-discussion This issue/PR requires more discussion with community. p1

Comments

@shellscape
Copy link

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

@shellscape shellscape added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 10, 2023
@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label Mar 10, 2023
@pahud pahud added needs-discussion This issue/PR requires more discussion with community. and removed needs-triage This issue or PR still needs to be triaged. bug This issue is a bug. labels Mar 10, 2023
@pahud
Copy link
Contributor

pahud commented Mar 10, 2023

Thank you for the feedback. I will bring it up to the core team for further discussion.

@pahud pahud added p2 feature-request A feature should be added or improved. effort/medium Medium work item – several days of effort labels Mar 14, 2023
@otaviomacedo otaviomacedo added the @aws-cdk/core Related to core CDK functionality label Apr 27, 2023
@scanlonp scanlonp added p1 and removed p2 labels Feb 13, 2024
@soucema9 soucema9 linked a pull request May 3, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality aws-cdk-lib Related to the aws-cdk-lib package effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. needs-discussion This issue/PR requires more discussion with community. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants