Repository navigation
Description
Description
Local template resolution does not preserve backslashes in values substituted by Fn::Sub. For a parameter such as C:\project\data, the local provider leaves the environment variable as an unresolved intrinsic expression. Some values, such as a literal \n, are silently changed instead.
Steps to reproduce
From a development checkout at 2fd518eeb5ede1ff85522e2d3c39999782322759, run this Python snippet. It exercises the local template provider without AWS credentials or a container runtime:
from samcli.lib.providers.sam_base_provider import SamBaseProvider
template = {
"Transform": "AWS::Serverless-2016-10-31",
"Parameters": {"DataRoot": {"Type": "String", "Default": r"C:\project\data"}},
"Resources": {
"ExampleFunction": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Runtime": "python3.12",
"Handler": "index.handler",
"InlineCode": 'def handler(event, context): return "ok"',
"Environment": {"Variables": {"DATA_PATH": {"Fn::Sub": r"${DataRoot}\cache"}}},
},
}
},
}
resolved = SamBaseProvider.get_template(template, {})
value = resolved["Resources"]["ExampleFunction"]["Properties"]["Environment"]["Variables"]["DATA_PATH"]
print(repr(value))
assert value == r"C:\project\data\cache"Observed result
The assertion fails. The value remains:
{'Fn::Sub': '${DataRoot}\\cache'}The underlying handle_fn_sub passes the resolved value to re.sub as its replacement string, which raises re.error: bad escape \p at position 2. The local provider's permissive resolution catches the exception and preserves the unresolved expression. A replacement containing \1 raises an invalid-group-reference error; \n and doubled backslashes can be silently transformed.
Expected result
The value is the string C:\project\data\cache, with its backslashes preserved. Resolved parameter and variable-map values should be inserted literally, consistent with the Fn::Sub substitution contract.
Additional environment details
- Windows, Python 3.12.13; development SAM CLI version 1.171.0 at the commit above.
- No region-specific behavior or AWS API calls are involved.
- CLI debug output also reports
Unable to resolve property DATA_PATH ... Leaving as is; a complete local invocation was not run because no container runtime was available.
Activity
vinsymoyya commentedon Nov 3, 2026
Opened #9397 with a fix that inserts resolved
Fn::Subvalues literally, preserving backslashes. All six new regressions fail against the original code and pass with the fix, including the real local template provider case. The fullmake prrun passed with 9,758 tests and 94.09% coverage.valerena commentedon Nov 4, 2026
Thanks for the report and the contribution. I just approved the CI run in the PR and we'll take a look at it soon.
github-actions commentedon Nov 5, 2026
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
reedham-aws commentedon Nov 5, 2026
This will be released in v1.172.0.