Skip to content

Commit 1cc9087

Browse files
committed
fix: accept digit-leading loop names in is_sam_generated_mapping
A ForEach loop named Fn::ForEach::1stBatch produces a mapping name like SAMCodeUri1stBatch. The character after the prefix (SAMCodeUri) is '1', which failed the uppercase-only check. This caused _update_sam_mappings_relative_paths to skip the mapping (broken artifact paths in build output) and _create_deploy_error to miss it (raw CFN error instead of helpful re-package guidance). Now accepts digits as well as uppercase letters after the prefix. All SAM-generated prefixes end in a letter (CodeUri, ImageUri, etc.) so a digit unambiguously indicates the start of the nesting path.
1 parent 77d83d1 commit 1cc9087

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

samcli/lib/cfn_language_extensions/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ def is_sam_generated_mapping(mapping_name: str) -> bool:
8787
return False
8888
if mapping_name.startswith(prefix):
8989
nxt = mapping_name[len(prefix)]
90-
if "A" <= nxt <= "Z":
90+
# Accept uppercase letter (PascalCase nesting path) or digit
91+
# (loop names like "1stBatch" produce SAMCodeUri1stBatch).
92+
if ("A" <= nxt <= "Z") or ("0" <= nxt <= "9"):
9193
return True
9294
return False
9395

tests/unit/commands/deploy/test_exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def test_sam_generated_names_match(self):
177177
"SAMContentUriLayers",
178178
"SAMDefinitionUriEnvsFunctions",
179179
"SAMImageUriFunctionsApi",
180+
# Digit-leading loop name: Fn::ForEach::1stBatch
181+
"SAMCodeUri1stBatch",
180182
):
181183
with self.subTest(name=name):
182184
self.assertTrue(is_sam_generated_mapping(name))

0 commit comments

Comments
 (0)