-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cdk synth generates only json files when used with -o #2965
cdk synth generates only json files when used with -o #2965
Comments
Related to #2848 |
Looking at #2848, there might be some conflation going on between the |
When using `cdk synth -o` the templates emitted to the cloud assembly are always in JSON. This change improves the documentation for `--json`, which only applies when `-o` is not used. Closes #2965
When using `cdk synth -o` the templates emitted to the cloud assembly are always in JSON. This change improves the documentation for `--json`, which only applies when `-o` is not used. Closes #2965
Is there now a way to synthesize yaml files of all stacks with |
Currently there isn’t. Can you further describe your use case? Why isnt JSON sufficient? Are these templates inspected by humans? |
@eladb what we do is we use CDK in codepipeline to generate cloudformation templates. Our buildspec contains something like this:
These templates are then used in different stages of codepipeline for updating different parts of our infra. For us it would also make sense that there would be I'm also interested if our approach has something that could be improved :) For now, this has worked quite well while parts of the infra are YAML and parts are CDK which is synthetized as part of pipeline process. |
Hey @markusl! Thanks for the details. The command The default output directory is now So the only difference for you would be: $ cdk synth
$ ls cdk.out
stack1-test.template.json
stack2-test.template.json
stack1-prod.template.json
stack2-prod.template.json YAML is JSON, so you could use these files anywhere that accepts YAML. As for how to set up CI/CD for CDK apps, we have some initial experimental work in the app-delivery module, and a pending PR. Closing for now. Please reopen if you see fit. |
Honestly, current workflow is somewhat confusing (reference: #2636 (comment)). If I have a single stack and I run Also, in our CI/CD pipeline we have |
After chatting with @eladb on Gitter... we talked about having the ability to pass the i.e.: |
+1 our ops team review the changes before the pipeline runs out the new infrastructure. Everything they do is in yaml so it would be helpful for them if it was in the same "language". |
This is not something we will likely support. It should trivial to convert the templates from |
Never the less what you want to do. CDK help is stating it wrong: > cdk synth --help
cdk synthesize [STACKS..]
Synthesizes and prints the CloudFormation template for this stack
Options:
[...]
--json, -j Use JSON output instead of YAML when templates are
printed to STDOUT [boolean] [Standard: false]
[...]
--output, -o Emits the synthesized cloud assembly into a directory
(default: cdk.out) [string]
[...] There is nothing stated about ...:
|
Furthermore on this issue. If i want to use SAM together with CDK, does SAM accept JSON and if so... how to tell it that its not template.yaml but some stack json in cdk.out.? The documentation (https://docs.aws.amazon.com/cdk/latest/guide/tools.html#sam) about SAM <-> CDK Interop says nothing about JSON. Update: Forget my question. Its possible via: |
JSON is valid YAML for all intents and purposes. |
YAML is much easier to read for the human eye. Could be useful to have an explicit YAML option for the situations when the app needs to be distributed as a template. |
All you have to do is to run
Its prints std output in template.yaml |
thanks, this is what I was searching |
We don’t have plans to output YAML to cdk.out
The
cdk.out
directory is a build artifact and generally intended to be read by machines and not by humans. As such we want to make sure it’s contents are deterministic and consistent and YAML is less stable then JSON (there are quirks related to yaml version, parsing, multi-line, etc).Any yaml parser should be able to read json out of the box because YAML is designed as a superset of json (all json is valid yaml).
If you need to convert json to human readable yaml, there are many many tools you could use.
Original post
Describe the bug
cdk synth ignores -j option when used with -o. It will always produce json files even if -j is false or not present. As a result, it is not possible to synthesize yaml files in a given directory.
To Reproduce
cdk synth -o stacks
cdk synth -j false -o stacks
Expected behavior
There should be yaml files in the stacks dir.
Version:
The text was updated successfully, but these errors were encountered: