aws / aws/aws-cdk

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

Open
#24,570 1 comment 0 reactions 0 assignees View on GitHub
@aws-cdk/core effort/medium feature-request needs-discussion p1
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

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 https://github.com/aws/aws-cdk/blob/15cb919fab9d20d0e8f0485662131cbb10980269/packages/%40aws-cdk/core/lib/stage.ts#L13-L43, `env` allows setting the region from which all other resources in the stage will use.

Even when casting `as any` to force `env` into `App`s constructor, `App` ignores `props` as a whole and only passes `outdir` as can be seen here: https://github.com/aws/aws-cdk/blob/15cb919fab9d20d0e8f0485662131cbb10980269/packages/%40aws-cdk/core/lib/app.ts#L160-L162

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_

Contributor guide

Open the contributing guide

Research direction

Start with the linked definitions in packages/@aws-cdk/core/lib/stage.ts and packages/@aws-cdk/core/lib/app.ts, especially StageProps, AppProps, and the App constructor. Check how CDK_DEFAULT_REGION is read and how the current default reaches stacks; done means App can configure the stage region, uses the environment value when appropriate, and gives the requested divergence guidance.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.