# Persist Template Context ## Overview Procedure for embedding architectural intent and design rationale into CloudFormation templates so that future sessions (human or AI) can understand WHY the stack exists and WHY each resource is configured the way it is. Uses the `Metadata."com.aws.cloudformation.Context"` schema when no other convention exists: - **Template Description** (1,024 bytes max): One-sentence summary of the stack's purpose and key design decision — the native CloudFormation Description field captures stack purpose. - **Template-level Metadata."com.aws.cloudformation.Context"** (optional): Cross-cutting context that applies broadly, stated ONCE (DRY) rather than repeated per resource — `arch` (system shape), `must` (cross-cutting constraints, array), `ref` (pointers to external context files, template level only), `owner` (contact). - **Resource-level Metadata."com.aws.cloudformation.Context"**: Per-resource rationale — `why` (purpose + notable choices + rejected alternatives), `must` (hard constraints/invariants, array), `mutable` (resource-level DEFAULT change-safety, one token: `must-never-change|change-with-constraints|review-required|free-to-tune`), `mutability` (OPTIONAL sparse override map — keys = CFN property names, only properties that DEVIATE from the `mutable` default, same enum), `trust`, `deps`. **Decision rule:** Will violating it break something? → `must`. Otherwise → `why`. There is no separate decisions/constraints split. **Caveman shorthand:** Use short keys, telegraphic values (symbols like `>=`, `->`, `x`, `&`), abbreviations (`fn`, `msg`, `dup`, `cfg`). Never restate the resource Type, logical id, property values, or the resource's `Description` property. **Tiers:** Always emit T1 (`why` + `must` on significant resources; Description for stack purpose). Add T2 (`mutable`, `arch` in `why`) if budget allows. Add T3 (`trust`, `deps`) when warranted. If the template nears 1 MB, shed in order: `trust` → `deps` → `mutable` on non-critical → trim `why` to significant resources → last resort externalize via `ref`. NEVER drop `must` on coupled/security/stateful resources. Measure the current template body in bytes (`wc -c