[cli] read context from ~/.cdk.json
When using ~/.cdk.json the aws-cdk:enableDiffNoFail context item doesn't seem to get populated during a diff, resulting in exit code 1.
Reproduction Steps
(Command outputs trimmed for brevity)
+ ls -al ~/
total 52
drwx------ 1 root root 4096 Oct 12 12:18 .
drwxr-xr-x 1 root root 4096 Oct 12 12:18 ..
-rw-rw-rw- 1 root root 97 Oct 9 15:30 .cdk.json
+ cat ~/.cdk.json
{
"app": "python3 /deploy/app.py",
"context": {
"aws-cdk:enableDiffNoFail": "true"
}
}
+ cdk diff -v --no-color
(see outputs below)
What did you expect to happen?
The output for diff should include the aws-cdk:enableDiffNoFail setting in the context and CDK_CONTEXT_JSON sections. cdk diff should exit 0.
This works correctly when explicitly setting the option with -c aws-cdk:enableDiffNoFail=true:
+ cdk diff -v --no-color -c aws-cdk:enableDiffNoFail=true
CDK toolkit version: 1.66.0 (build 459488d)
Command line arguments: {
_: [ 'diff' ],
v: 1,
verbose: 1,
color: false,
c: [ 'aws-cdk:enableDiffNoFail=true' ],
context: [ 'aws-cdk:enableDiffNoFail=true' ],
...
}
CLI argument context: aws-cdk:enableDiffNoFail=true
~/.cdk.json: {
"app": "python3 /deploy/app.py",
"context": {
"aws-cdk:enableDiffNoFail": "true"
}
}
merged settings: {
versionReporting: true,
pathMetadata: true,
output: 'cdk.out',
app: 'python3 /deploy/app.py',
context: { 'aws-cdk:enableDiffNoFail': 'true' },
assetMetadata: true,
toolkitBucket: {},
staging: true,
bundlingStacks: [ '*' ]
}
...
context: {
'aws-cdk:enableDiffNoFail': 'true',
'aws:cdk:enable-path-metadata': true,
'aws:cdk:enable-asset-metadata': true,
'aws:cdk:version-reporting': true,
'aws:cdk:bundling-stacks': [ '*' ]
}
outdir: cdk.out
env: {
CDK_DEFAULT_REGION: 'us-east-1',
CDK_DEFAULT_ACCOUNT: 'XXXXXX',
CDK_CONTEXT_JSON: '{"aws-cdk:enableDiffNoFail":"true","aws:cdk:enable-path-metadata":true,"aws:cdk:enable-asset-metadata":true,"aws:cdk:version-reporting":true,"aws:cdk:bundling-stacks":["*"]}',
CDK_OUTDIR: 'cdk.out',
CDK_CLI_ASM_VERSION: '6.0.0',
CDK_CLI_VERSION: '1.66.0'
}
What actually happened?
This option was missing in the diff output when the cli flag is removed, despite it still being in ~/.cdk.json and acknowledged earlier in the output (see merged_settings:). The cdk diff command exits with code 1.
+ cdk diff -v --no-color
CDK toolkit version: 1.66.0 (build 459488d)
Command line arguments: {
...
}
~/.cdk.json: {
"app": "python3 /deploy/app.py",
"context": {
"aws-cdk:enableDiffNoFail": "true"
}
}
merged settings: {
versionReporting: true,
pathMetadata: true,
output: 'cdk.out',
app: 'python3 /deploy/app.py',
context: { 'aws-cdk:enableDiffNoFail': 'true' },
assetMetadata: true,
toolkitBucket: {},
staging: true,
bundlingStacks: [ '*' ]
}
...
context: {
'aws:cdk:enable-path-metadata': true,
'aws:cdk:enable-asset-metadata': true,
'aws:cdk:version-reporting': true,
'aws:cdk:bundling-stacks': [ '*' ]
}
outdir: cdk.out
env: {
CDK_DEFAULT_REGION: 'us-east-1',
CDK_DEFAULT_ACCOUNT: 'XXXXXX',
CDK_CONTEXT_JSON: '{"aws:cdk:enable-path-metadata":true,"aws:cdk:enable-asset-metadata":true,"aws:cdk:version-reporting":true,"aws:cdk:bundling-stacks":["*"]}',
CDK_OUTDIR: 'cdk.out',
CDK_CLI_ASM_VERSION: '6.0.0',
CDK_CLI_VERSION: '1.66.0'
}
Environment
- CLI Version: 1.66
- Framework Version:
- Node.js Version: 12.18.4
- OS: Alpine 3.12.0
- Language (Version): Python (3.8.6)
Other
This is :bug: Bug Report
I ran into this bug too. The expected behavior is clearly documented at https://docs.aws.amazon.com/cdk/latest/guide/context.html
Context values are made available to your AWS CDK app in six different ways:
- ...
- In the context key of your ~/.cdk.json file.
@rix0rrr can you please retag it to bug?
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.