aws / aws/modern-data-architecture-accelerator

CI_SUPPLIED_TARGET_REGION vs CDK_DEPLOY_REGION mismatch leaves stack.env.region undefined, breaks cdk diff under cdk-lib >=2.258

Open
#69 4 comments 0 reactions 1 assignee Claimed by @suddash24 View on GitHub
Dominant language
TypeScript
Stars
80
Forks
29
PR merge metrics
No merged PRs in 30d

Description

## Description

There is an environment variable name mismatch between the MDAA CLI (`@aws-mdaa/cli`) and the MDAA app framework (`@aws-mdaa/app`) that causes `stack.env.region` to be **undefined** at synthesis when the target region is specified. This was latent under `aws-cdk-lib <= 2.220` but becomes a hard failure under `aws-cdk-lib >= 2.258` because CDK attempts an eager environment-property lookup.

## Root Cause

**The CLI** (`packages/cli/lib/mdaa-cli.ts:1025-1027`) exports:

```
export CDK_DEPLOY_REGION=eu-west-2
export AWS_DEFAULT_REGION=eu-west-2
```

**The app framework** (`packages/apps/core/app/lib/app.ts:188-189`) reads:

```typescript
this.deployRegion = process.env.CI_SUPPLIED_TARGET_REGION || process.env.CDK_DEFAULT_REGION;
```

Neither `CI_SUPPLIED_TARGET_REGION` nor `CDK_DEFAULT_REGION` is ever set by the CLI. The stack is then created (`app.ts:488-495`) with:

```typescript
env: {
region: this.deployRegion, // undefined
account: this.deployAccount, // resolves from CDK_DEPLOY_ACCOUNT
}
```

This produces `env = { account: "", region: undefined }` — an **incomplete environment** where the account is concrete but the region is not.

## Impact

When a downstream construct accesses `this.region` (e.g. `ServicePrincipal(`dms.${this.region}.amazonaws.com`)` in `dataops-dms-l3-construct.ts:431`), CDK must resolve the region:

- **cdk-lib <= 2.220**: returns a deferred token — no AWS call is made, works fine.
- **cdk-lib >= 2.258** (PR #18277, CDK CLI >= 2.11.0): `cdk diff` attempts an eager environment-property lookup via the bootstrap lookupRole. In CI environments without AWS credentials, this fails with:

> "Need to perform AWS calls for account , but no credentials have been configured"

## Affected Versions

- `@aws-mdaa/app` >= 1.7.0 (bundles aws-cdk-lib >= 2.258.0)
- `@aws-mdaa/cli` >= 1.7.0
- All modules using `CI_SUPPLIED_TARGET_REGION` in their app framework

## Suggested Fix

Align the env-var names so the CLI exports the variable the app framework reads. The app framework at `app.ts:189` should read the variable the CLI actually sets:

Both approaches work — pick whichever is less disruptive:

**Option A** — Fix the app framework to read what the CLI exports:

```typescript
this.deployRegion = process.env.CDK_DEPLOY_REGION || process.env.AWS_DEFAULT_REGION || process.env.CDK_DEFAULT_REGION;
```

**Option B** — Fix the CLI to export what the app framework expects:

```typescript
cdkEnv.push(
`export CDK_DEPLOY_REGION=${region}`,
`export AWS_DEFAULT_REGION=${region}`,
`export CI_SUPPLIED_TARGET_REGION=${region}`
);
```

## Workaround (for users blocked today)

Pass `--no-lookups` to `cdk diff` or set `CI_SUPPLIED_TARGET_REGION` / `CDK_DEFAULT_REGION` in the environment before invoking MDAA commands.

## References

- Source: `packages/apps/core/app/lib/app.ts` line 189
- Source: `packages/cli/lib/mdaa-cli.ts` lines 1022-1034
- CDK PR #18277 — "diff now uses the lookup Role for new-style synthesis"

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.