aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

[CLI] Where can I find an example of ~/.cdk.json file configuration

Open robertd opened this issue 6 years ago • 9 comments

:question: General Issue

The Question

Hello,

I'm trying to use newly issued fix for progress bar vs events on a more global level. I've tried creating ~/.cdk.json but I can't seem to get it right. I haven't seen any examples in docs showing how to properly configure ~/.cdk.json globally.

Can you please provide an example how to do this?

Thanks!

Environment

  • CDK CLI Version: 1.63.0
  • Node.js Version: v14.11.0
  • OS: OSX Mojave
  • Language (Version): TypeScript (3.8.3)

robertd avatar Sep 18 '20 17:09 robertd

You should have a cdk.json file in your directory, it is created by the cdk init when creating a cdk application. In any case you can execute cdk init in an empty folder to get the file.

NetaNir avatar Sep 18 '20 23:09 NetaNir

Hello, @NetaNir. I'm not referring to a new project here. I was referring to a global environment (~/.cdk.json) as stated in the documentation (5th bullet).

https://docs.aws.amazon.com/cdk/latest/guide/context.html

image

I'd really like to declare variables on a global level so that all of my projects are using --progress=events setting introduced in https://github.com/aws/aws-cdk/pull/9623.

robertd avatar Sep 19 '20 03:09 robertd

@NetaNir Here are the contents of my ~/.cdk.json file, but they're being ignored when I run cdk init app in a new project. What am I doing wrong?

{
  "context": {
    "language": "typescript",
    "progress": "events"
  }
}

Edit: I see that ~/.cdk.json is being loaded as a default in https://github.com/aws/aws-cdk/blob/master/packages/aws-cdk/lib/settings.ts#L12. However, it seems to me that if local cdk.json exists, then global config (in ~/.cdk.json) gets overridden by the local one (in cdk.json). Shouldn't just local be merged into global instead?

robertd avatar Sep 19 '20 03:09 robertd

@robertd Thanks for debugging this. I think that this is the expected behavior, the local cdk.json take precedence over the global one. Merging logic will most likely be more confusing. We definitely need to document the order in which the context values are populated to out docs. @Jerry-AWS

NetaNir avatar Sep 22 '20 05:09 NetaNir

Merge logic may be confusing, but without it, ~/.cdk.json is pretty well useless. As a developer who works on a number of different small projects in CDK, I would expect ~/.cdk.json to contain global configuration values - such as setting progress to bar vs. events, or a default language, and the local cdk.json to contain local configuration and overrides. Otherwise, as I said above, what's the point of ~/.cdk.json?

kpeters-cbsi avatar Nov 05 '20 18:11 kpeters-cbsi

@kpeters-cbsi @robertd Your comments on expected behavior of merging context from ~/.cdk.json are relating to #10823 (... where I have added a PR)

bitbauer avatar Jan 07 '21 12:01 bitbauer

@bitbauer Sweet. Thank you. 🙏

robertd avatar Jan 07 '21 14:01 robertd

Closed by #12394

robertd avatar Jan 13 '21 00:01 robertd

⚠️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.

github-actions[bot] avatar Jan 13 '21 00:01 github-actions[bot]