(aws-cdk): CLI diff prints the diff output into stderr (or stdout with --ci) together with log messages
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
I'd like to get just the diff output from `cdk diff` command. It appears that AWS CDK CLI seems to print both the diff and various log messages into `stderr`. I've taken a look at some of the related issues: https://github.com/aws/aws-cdk/issues/7717, https://github.com/aws/aws-cdk/issues/1638, and https://github.com/aws/aws-cdk/issues/10417. Seems that no combination of `--quiet`, `--ci`, or `--no-color` helps.
The diff `stderr` always contains log messages like:
```
Hold on while we create a read-only change set to get a diff with accurate replacement information (use --no-change-set to use a less accurate but faster template-only diff)
```
Of course I can clean that myself, but I feel that this is a sort of a bug.
If I provide `--ci` option or `CI=true` env var, then the log messages and diff both go to `stdout`.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
_No response_
### Expected Behavior
Log messages that are not relevant to diff output should go to `stderr` and only the relevant diff output should go to `stdout`.
### Current Behavior
Currently `cdk diff` prints log messages to `stderr`, including:
```
Hold on while we create a read-only change set to get a diff with accurate replacement information (use --no-change-set to use a less accurate but faster template-only diff)
```
Unless `--ci` or `CI=true` passed, in which case all the output goes to `stdout`.
### Reproduction Steps
1. Create any stack
2. Deploy the stack
3. Introduce some changes
4. Run `cdk diff 2>output.log`
5. View `output.log` which will contain debug messags
### Possible Solution
I think it would be reasonable change to just forward log messages into `stderr` and the actual diff output to `stdout`.
Though this would require modifications to: https://github.com/aws/aws-cdk/blob/f3bc16c7b9f1d58318a451d8640a0f8f07f4ffcb/packages/aws-cdk/lib/api/util/cloudformation.ts#L346
If a change to the existing default behaviour is not possible, then maybe some additional CLI option to control this?
### Additional Information/Context
_No response_
### CDK CLI Version
2.155.0 (build 34dcc5a)
### Framework Version
_No response_
### Node.js Version
v20.12.2
### OS
macOS Sonoma 14.6.1
### Language
TypeScript
### Language Version
5.5.4
### Other information
_No response_
Contributor guide
Research direction
Start in packages/aws-cdk/lib/api/util/cloudformation.ts around line 346, then reproduce the issue with `cdk diff 2>output.log` and compare it with `--ci` or `CI=true`. Done means diff output is separated from unrelated log messages according to the expected behavior, with the relevant stream verified by the reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, node.js, typescript
- Domain
- cli, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100