Skip to content

Commit f05f2d4

Browse files
committed
docs(cfn-lang-ext): document AWS::Include processing order vs language extensions
Add a section explaining that sam package processes Fn::Transform: AWS::Include before language-extension expansion, mirroring CloudFormation's server-side transform ordering. This means AWS::Include Location rewrites work correctly even when the include lives buried inside language-extension functions like Fn::ToJsonString or Fn::ForEach bodies.
1 parent b49a40d commit f05f2d4

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

docs/cfn-language-extensions.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,22 @@ The following intrinsic functions are resolved locally during expansion:
263263

264264
Functions that require deployed resources (`Fn::GetAtt`, `Fn::ImportValue`, `Fn::GetAZs`) are preserved for CloudFormation to resolve at deploy time.
265265

266+
## AWS::Include processing order
267+
268+
When a template uses both `Fn::Transform: AWS::Include` and
269+
`Transform: AWS::LanguageExtensions`, SAM CLI processes the inline
270+
`AWS::Include` macros **before** running language-extension expansion
271+
locally. This mirrors CloudFormation's server-side transform pipeline,
272+
where `Fn::Transform` macros are resolved before
273+
`AWS::LanguageExtensions`.
274+
275+
The practical effect is that `AWS::Include` `Location` rewrites work
276+
correctly even when the include lives buried inside language-extension
277+
functions like `Fn::ToJsonString` or `Fn::ForEach` bodies, because the
278+
include is rewritten while still structurally visible — before
279+
`Fn::ToJsonString` collapses subtrees into JSON-string literals or
280+
`Fn::ForEach` expands resources.
281+
266282
## Validation errors
267283

268284
The following template issues are caught locally before the SAM transform runs:
@@ -272,7 +288,7 @@ The following template issues are caught locally before the SAM transform runs:
272288
| The `Fn::ForEach` value is malformed — not a list, doesn't have exactly 3 elements, or has a non-string loop identifier. | `Fn::ForEach::<key> layout is incorrect` (raised as `InvalidTemplateException`; see `samcli/lib/cfn_language_extensions/processors/foreach.py`). |
273289
| More than 5 levels of `Fn::ForEach` are nested. | `Fn::ForEach nesting depth of <N> exceeds the maximum allowed depth of 5. CloudFormation supports up to 5 nested Fn::ForEach loops.` |
274290
| The collection resolves to an empty list (e.g., a `CommaDelimitedList` parameter with `Default: ""`). | No error — the loop is silently skipped and no resources are emitted. |
275-
| The `!Ref` in the collection points at a parameter that is not declared in the template. | No error in the typical `sam build` / `sam package` flow. SAM CLI runs intrinsic resolution in PARTIAL mode and preserves the unresolved `{"Ref": "<name>"}`. CloudFormation will reject the unresolved ref at deploy time. |
291+
| The `!Ref` in the collection points at a parameter that is not declared in the template. | No error in the typical `sam build` / `sam package` flow. SAM CLI runs intrinsic resolution in PARTIAL mode and preserves the unresolved `{"Ref": "<name>"}`. At deploy time, CloudFormation will resolve it server side. |
276292

277293
## Limitations
278294

0 commit comments

Comments
 (0)