-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
cli: ability to pass context values through file #23911
Comments
I have submitted a PR #23912 implementing the feature, but since I have never worked on nodejs, need someone to address the tests. |
You can use both |
@peterwoodworth the objective here is maintaining and passing environment specific cdk.context.json. Separate files like cdk.context.dev.json, cdk.context.stage.json, cdk.context.prod.json. |
I'm not sure how having multiple files here would be more helpful for organizing context. Context can contain objects, so you can specify context like so:
and reference it like so:
This can be generalized such that all you need to change is what's passed in to If you can provide more information about your use case to show why your proposal would be helpful (and why this approach wouldn't work), I'd love to hear it |
Hi @peterwoodworth Please see #2371 for history and comments #2371 (comment) #2371 (comment) |
Putting everything in the same context file might not be preferable in every scenario. Say for eg prod. I would like to keep my prod configuration out of git. It could probably reside on S3, so only people who have access can download the file and refer the same. This is just an example and everything can have an alternative solution. Its just about what feels natural to work with. |
I spent some time searching for this feature and found this Issue. I'll chime in here with a more "basic" use-case, which is: "just because I like it that way." Development workflow feels cleaner and easier to navigate when each environment has its own unique file, as opposed to one giant file where I'm scrolling around. Things get extra long when you start adding in multiple regions and each region has certain unique values. Terraform has .tfvar files, Serverless Framework has built-in syntax for reading in any number of customized YAML option files, etc. --- it's not an entirely valueless feature. With those tools, I follow a format like $ENV_$REGION, so like dev_ap-northeast-1.tfvars, etc., then those two values are used at runtime (i.e. in a CI pipeline) to evaluate which file to load. The same concept can be used with the single context object in CDK, but again, it just makes for a better developer user experience being able to compartmentalize each into their own file. |
yeah this is long due. it's just like being able to have .env.dev and .env.prod. it's not even just for the context, but just to have an isolated prod cdk.json that won't be touched. |
Describe the feature
Context variables allow passing parameters to the cdk command. But since they need to be specified individually, reruns become a challenge.
Keep track of what values have been used previously and pass them again.
If there are multiple environments it become even more challenging and tedious.
Use Case
Reruns require me to remember and pass the same variables everytime. Also specifying each variable everytime is tedious.
Proposed Solution
The ability to store these values in a json file and passing it to the cli would be great feature for reusability and maintenance.
cdk deploy --context-file cdk.dev.json
or
cdk deploy --context-file cdk.stage.json -c "vpcEnv=qa"
Other Information
No response
Acknowledgements
CDK version used
2.62.2
Environment details (OS name and version, etc.)
MacOS Ventura
The text was updated successfully, but these errors were encountered: