diff --git a/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py b/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py index 4788ba9c97..ff013653f8 100644 --- a/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py +++ b/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py @@ -160,8 +160,14 @@ def get_default_pseudo_resolver(self): def get_default_attribute_resolver(self): return {"Ref": lambda logical_id: logical_id, "Arn": self.arn_resolver} - @staticmethod - def get_default_type_resolver(): + def handle_function_alias_type(self, logical_id): + node = self._resources.get(logical_id).get("Properties").get("FunctionName") + + function_id = self.resolve_symbols(node.get("Ref"), IntrinsicResolver.REF) + functionArn = self.arn_resolver(function_id) + return functionArn + + def get_default_type_resolver(self): return { "AWS::ApiGateway::RestApi": { "RootResourceId": "/" # It usually used as a reference to the parent id of the RestApi, @@ -169,6 +175,9 @@ def get_default_type_resolver(): "AWS::Lambda::LayerVersion": { IntrinsicResolver.REF: lambda logical_id: {IntrinsicResolver.REF: logical_id} }, + "AWS::Lambda::Alias": { + IntrinsicResolver.REF: self.handle_function_alias_type, + }, "AWS::Serverless::LayerVersion": { IntrinsicResolver.REF: lambda logical_id: {IntrinsicResolver.REF: logical_id} }, diff --git a/tests/unit/lib/intrinsic_resolver/test_intrinsics_symbol_table.py b/tests/unit/lib/intrinsic_resolver/test_intrinsics_symbol_table.py index 236697aaa1..449092b2fb 100644 --- a/tests/unit/lib/intrinsic_resolver/test_intrinsics_symbol_table.py +++ b/tests/unit/lib/intrinsic_resolver/test_intrinsics_symbol_table.py @@ -1,12 +1,11 @@ from unittest import TestCase - from unittest.mock import patch from parameterized import parameterized -from samcli.lib.intrinsic_resolver.invalid_intrinsic_exception import InvalidSymbolException from samcli.lib.intrinsic_resolver.intrinsic_property_resolver import IntrinsicResolver from samcli.lib.intrinsic_resolver.intrinsics_symbol_table import IntrinsicsSymbolTable +from samcli.lib.intrinsic_resolver.invalid_intrinsic_exception import InvalidSymbolException class TestIntrinsicsSymbolTablePseudoProperties(TestCase): @@ -91,6 +90,25 @@ def test_default_type_resolver_function(self): self.assertEqual(result, "MyApi") + def test_default_type_resolver_function_alias(self): + template = { + "Resources": { + "TestFunction17441592": { + "Type": "AWS::Lambda::Function", + }, + "TestFunctionAlias31D71541": { + "Type": "AWS::Lambda::Alias", + "Properties": { + "FunctionName": {"Ref": "TestFunction17441592"}, + }, + }, + } + } + symbol_resolver = IntrinsicsSymbolTable(template=template) + result = symbol_resolver.resolve_symbols("TestFunctionAlias31D71541", "Ref") + + self.assertEqual(result, "arn:aws:lambda:us-east-1:123456789012:function:TestFunction17441592") + def test_custom_attribute_resolver(self): template = {"Resources": {"MyApi": {"Type": "AWS::ApiGateway::RestApi"}}} common_attribute_resolver = {"Arn": "test"}