feat(core): embed structured design context in synthesized templates (MetadataContext) - #38381
Open
satyakigh wants to merge 2 commits into
Open
feat(core): embed structured design context in synthesized templates (MetadataContext)#38381satyakigh wants to merge 2 commits into
satyakigh wants to merge 2 commits into
Conversation
Contributor
|
👋 It looks like your PR description follows the template but is missing a valid issue number in the first section. PRs without a linked issue will receive lower priority for review and merging. Please update the description to include a reference like |
aws-cdk-automation
previously requested changes
Jul 22, 2026
aws-cdk-automation
dismissed
their stale review
July 22, 2026 23:51
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
satyakigh
force-pushed
the
context-constructs
branch
from
July 22, 2026 23:51
8da308b to
517cab1
Compare
mrgrain
previously requested changes
Jul 23, 2026
mrgrain
left a comment
Contributor
There was a problem hiding this comment.
Hey, since the feature is already stable, the Mixin should go straight into aws-cdk-lib as well. The preview package is being phased out.
aws-cdk-automation
temporarily deployed
to
automation
July 23, 2026 04:47 — with
GitHub Actions
Inactive
aws-cdk-automation
temporarily deployed
to
automation
July 23, 2026 04:48 — with
GitHub Actions
Inactive
satyakigh
force-pushed
the
context-constructs
branch
from
July 23, 2026 14:28
b362a0a to
b6106b6
Compare
Contributor
Author
Sounds good, updated |
satyakigh
force-pushed
the
context-constructs
branch
from
July 26, 2026 19:47
b6106b6 to
5caa8fa
Compare
satyakigh
force-pushed
the
context-constructs
branch
from
July 27, 2026 14:44
5caa8fa to
553ae1b
Compare
satyakigh
force-pushed
the
context-constructs
branch
from
July 31, 2026 04:10
553ae1b to
64700e1
Compare
…and aspect + mixins to set context on a resource and template
…ib core The mixins-preview package is being phased out and the feature is stable, so the Mixin ships directly in aws-cdk-lib alongside the MetadataContext facade (review feedback). - MetadataContextMixin now lives in core/lib/mixins/ and is exported flat from aws-cdk-lib (a top-level 'mixins' jsii submodule is not possible: JSII5011 name conflict with the Mixins class), with an awslint exclusion for the mixin-namespace rule. - Unit test moved to core/test/mixins/, adapted to core's toCloudFormation convention. - Integ test moved to @aws-cdk-testing/framework-integ test/core/test/ with regenerated snapshot. - aws-cdk-lib README documents the mixin inline; all mixins-preview changes reverted.
satyakigh
force-pushed
the
context-constructs
branch
from
July 31, 2026 18:00
64700e1 to
80ec30c
Compare
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.
Issue # (if applicable)
Reason for this change
CloudFormation templates capture what infrastructure exists but not why — rationale, invariants, change-safety, and operational knowledge live in code comments, wikis, and people's heads, and are lost by the time someone (or an automated tool/agent) modifies the deployed template. A structured, advisory
Metadata.Contextschema defines where that knowledge belongs in the template, but CDK users have no way to author it. Since most production templates are CDK-synthesized, CDK needs a first-class authoring surface that emits the schema's frozen wire format.Description of changes
Two composable capabilities, following the feature-placement decision in
docs/AGENTS_CONSTRUCT_DESIGN.md(cross-cutting capability → aspect-backed facade + Mixin, not per-service L2 changes):MetadataContextfacade inaws-cdk-libcore (core/lib/metadata-context.ts, shared rendering/validation incore/lib/private/metadata-context-internal.ts) — mirrors theTags/RemovalPoliciespattern:MetadataContext.of(scope).add(props, options?)— resource-level context (why,must,mutable, sparsemutabilitymap,trust,ops,gaps,deps,failureModes). Cascades at synth time to primary resources (thedefaultChildchain), skipping incidental helper resources; nearest scope wins scalars, list fields union and de-duplicate. Options:applyToAllResources,includeResourceTypes/excludeResourceTypes, aspectpriority. Crosses stack boundaries intoNestedStacks, likeTags.MetadataContext.of(scope).addToTemplate(props)— template-level context (arch,must,refs,owner) merged into the enclosing stack's top-levelMetadata.ContextMutability,ContextTrustSource,ContextTrustConfidence; structsResourceContextProps,TemplateContextProps,ContextTrust,ContextRef. Trust defaults:AUTHORED/MEDIUM. ExplicitcfnResource.addMetadata('Context', ...)always wins over cascaded context.MetadataContextMixininaws-cdk-libcore (core/lib/mixins/metadata-context-mixin.ts) — imperative application to exactly the constructs you target via.with()orMixins.of(scope).apply(); delegates to the facade so both forms share one merge model. Exported flat fromaws-cdk-libbecause jsii forbids a top-levelmixinssubmodule (JSII5011 conflict with theMixinsclass); the awslintmixin-namespacerule is excluded for this one class inawslint.json(file-location and extends-base rules pass as-is).Docs: new "Metadata Context" section in the
aws-cdk-libREADME, covering both the facade and the Mixin.Describe any new or updated permissions being added
None. The change writes only to template
Metadatasections at synthesis time — no IAM policies, roles, grants, trust relationships, or resource policies are created or modified, and no runtime AWS calls are made.Description of how you validated changes
core/test/metadata-context.test.ts(rendering, cascade/merge semantics, primary-resource targeting incl. L2-styledefaultChildtrees and grouping constructs, NestedStack template + cascade behavior, filters, validation errors, wire-format conformance incl. a frozen-enum drift check); 6 tests for the mixin incore/test/mixins/metadata-context-mixin.test.ts. All assertions run against synthesized templates (toCloudFormationper core convention).Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license