Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AWS::Lambda::Alias type resolving #7833

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,24 @@ 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,
},
"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}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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"}
Expand Down
Loading