Repository navigation
fix(E1010): Resolve GetAtt to SAM generated resources - #4646
Merged
Merged
Conversation
SAM generated resources (a function's Version/Alias) are modeled as synthetic resources whose logical id contains a "." (MyFn.Version). A GetAtt shorthand is split on the first ".", so !GetAtt MyFn.Version.FunctionArn was resolved against the function itself rather than the synthetic Version resource, producing a false positive E1010. Re-associate the longest logical-id prefix that matches a known resource before validating the attribute, so the dotted synthetic id stays intact. Ordinary two-segment GetAtts and unresolved (Ref/Sub) resource names are left unchanged. A function without AutoPublishAlias still errors, since SAM generates no Version resource and the template would not deploy. aws-cloudformation#4644
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4646 +/- ##
=======================================
Coverage 94.61% 94.61%
=======================================
Files 432 432
Lines 15426 15437 +11
Branches 2991 2995 +4
=======================================
+ Hits 14595 14606 +11
Misses 453 453
Partials 378 378
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available
Fixes #4644
Description of changes
!GetAtt <Function>.Version.FunctionArnon anAWS::Serverless::Functionproduced a false positiveE1010since v1.54.0 (regression from removing the SAM translator in #4491):Root cause: SAM's generated
Version/Aliasresources are modeled as synthetic resources whose logical id contains a.(MyFn.Version, typeAWS::Lambda::Version), injected whenAutoPublishAlias/DeploymentPreferenceis present. A GetAtt shorthand is split on the first., soMyFn.Version.FunctionArnwas validated as attributeVersion.FunctionArnon the function itself instead of resolving against the syntheticMyFn.Versionresource.Fix: In
E1010, re-associate the longest logical-id prefix that matches a known resource before validating the attribute, keeping the dotted synthetic id intact. Ordinary two-segment GetAtts and unresolved (Ref/Sub) resource names are unaffected.Verified against the real
aws-sam-translator:AutoPublishAlias: SAM emitsAWS::Lambda::Versionand rewrites the GetAtt to it → now passes.E1010still (correctly) fires. The minimal template in the issue falls in this second case.Tests
test/unit/rules/functions/test_getatt.py.test/fixtures/templates/good/functions/getatt_serverless_function_version.yamlreproducing False positive E1010 AWS::Serverless::Function Version.FunctionArn not allowed for AWS::CloudFront::Distribution DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations[].LambdaFunctionARN #4644, registered intest_good_templates.py.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.