Repository navigation
Conversation
added 2 commits
December 1, 2026 21:19
The hand-authored config files can now be written as YAML, which lets them hold comments explaining why a setting or a feature flag is the way it is. JSON remains the default and nothing about it changes. - `cdk.yaml` and `~/.cdk.yaml` are read as alternatives to `cdk.json` and `~/.cdk.json`. `cdk.context.json` stays JSON only: it is a cache of context provider lookups that the CLI writes, not a file meant to be hand-edited. - Where both spellings exist the JSON one is read, exactly as today, and a warning names the file being ignored. A project that already has an unrelated `cdk.yaml` therefore keeps working. - `cdk flags --set` writes a YAML config back through the YAML document API, so the comments in the file survive a flag change. - `CdkAppMultiContext` resolves the same two spellings, so context held in a YAML config is visible to the programmatic API as well. closes aws/aws-cdk#15529
kidbrax
requested a deployment
to
integ-approval
December 1, 2026 23:14 — with
GitHub Actions
Waiting
aws-cdk-automation
enabled auto-merge
December 1, 2026 23:14
This branch is waiting to be deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes aws/aws-cdk#15529.
The hand-authored config files can now be written as YAML, so that they can carry comments explaining why a setting or a feature flag is the way it is. JSON remains the default, and nothing about it changes.
Scope
cdk.yamland~/.cdk.yamlare accepted as alternatives tocdk.jsonand~/.cdk.json.cdk.context.jsonstays JSON only.That split is deliberate, and it is narrower than the literal title of the issue (which asked for
cdk.context.yaml).cdk.context.jsonis a cache of context provider lookups that the CLI writes on every run, not a file meant to be hand-edited, so comments in it would have nowhere useful to live. The workaround posted in the issue thread — loading a YAML file and passing it in ascontext— is about the authored config too. Happy to widen this if maintainers disagree.This is not #632. That asks which context file is read, per environment; this is only about how the bytes of the two authored files are parsed. The code is adjacent but the two are independent.
Backwards compatibility
Where both spellings exist, the JSON one is read, exactly as it is today, and a warning names the file being ignored:
Erroring out would have been tidier, but it would break any project that already has an unrelated
cdk.yamlsitting next to itscdk.json, so JSON keeps winning. No feature flag seemed warranted, because no existing configuration changes meaning — a project with onlycdk.jsonbehaves identically. Please say if you would rather it was gated.Two places that needed more than a parser swap
cdk flags --setwrites the project config. It is the one code path that writes a hand-authored file. For YAML it now goes through theyamldocument API, so a flag change leaves the file's comments intact.CdkAppMultiContextreads the config independently of the CLI's ownConfiguration. It resolves the same two spellings, so context held in a YAML config is visible to the programmatic API as well.Notes
yaml@^2is already a production dependency of bothpackages/aws-cdkandpackages/@aws-cdk/toolkit-lib.toolkit-lib's public API. The shared helper lives inlib/util/config-file.tsand reaches the CLI throughapi-private.ts, so there is no API report change.cdk initstill generatescdk.json; YAML is opt-in by renaming and converting.Testing
Configurationlevel for settings, context,contextSourceFiles, the both-files warning, and the unchanged JSON path.aws-cdkand@aws-cdk/toolkit-libsuites run with no new failures; the failures that remain are present unchanged onmainin the same environment (bootstrap template fixtures,sdk-provider, and the init/migrate tests that need the .NET SDK).cdk contextin a directory holding only a commentedcdk.yamllists its context and names the file, and emits the warning above once acdk.jsonis added alongside.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license