Skip to content

fix(sub): resolve SAM generated Version/Alias references in Fn::Sub - #4798

Merged
kddejong merged 1 commit into
aws-cloudformation:mainfrom
moneytool:fix/sub-sam-autopublish-alias
Oct 23, 2026
Merged

kddejong merged 1 commit into
aws-cloudformation:mainfrom
moneytool:fix/sub-sam-autopublish-alias

Conversation

@moneytool

Copy link
Copy Markdown
Contributor

Issue #, if available: Fixes #4777

Description of changes:

  • Root cause: Sub._validate_string validates every dotted ${a.b} as {"Fn::GetAtt": "a.b"}. SAM's generated Version/Alias resources (when AutoPublishAlias or DeploymentPreference is set) are registered in the context as synthetic resources whose logical id contains a . (MyFunction.Version), so ${MyFunction.Version} / ${MyFunction.Alias} were checked as attributes of the function and reported E1019.
  • Change: if the full dotted name is itself a known resource, validate it as a Ref instead of a GetAtt. This mirrors fix(E1010): Resolve GetAtt to SAM generated resources #4646 for Fn::GetAtt. A function without AutoPublishAlias still errors, because SAM generates no such resource.
  • Tests: unit tests in test/unit/rules/functions/test_sub.py for AutoPublishAlias (Version, Alias, and ${MyFunction.Version.Version}), DeploymentPreference, and a function without either (still errors). Added the good template test/fixtures/templates/good/functions/sub_serverless_function_version.yaml to test_good_templates.py.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

SAM generated resources (a function's Version/Alias when
AutoPublishAlias or DeploymentPreference is set) are modeled as
synthetic resources whose logical id contains a "." (MyFn.Version).
Fn::Sub validated every dotted ${a.b} as a GetAtt, so
${MyFn.Version} and ${MyFn.Alias} were checked as attributes of the
function and reported E1019.

When the full dotted name is a known resource, validate it as a Ref
instead, matching how SAM resolves it. A function without
AutoPublishAlias still errors, since SAM generates no such resource.

Fixes aws-cloudformation#4777
@kddejong
kddejong force-pushed the fix/sub-sam-autopublish-alias branch from b379e85 to 4c459ae Compare October 23, 2026 21:29
@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.68%. Comparing base (6d2a6ad) to head (4c459ae).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4798   +/-   ##
=======================================
  Coverage   94.68%   94.68%           
=======================================
  Files         439      439           
  Lines       16004    16004           
  Branches     3108     3108           
=======================================
  Hits        15153    15153           
  Misses        468      468           
  Partials      383      383           
Flag Coverage Δ
unittests 94.67% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kddejong
kddejong merged commit a08bf36 into aws-cloudformation:main Oct 23, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E1019: ${MyFunction.Version} / ${MyFunction.Alias} in Fn::Sub reported for AWS::Serverless::Function with AutoPublishAlias since 1.54.0

2 participants