From 6188d82230e2fba243cf61e8f60457a028159fdb Mon Sep 17 00:00:00 2001 From: jonife <79116465+jonife@users.noreply.github.com> Date: Thu, 19 May 2022 16:35:27 -0500 Subject: [PATCH] Furl AutopublishAlias bug fix (#2378) * furl autopublishing bug fix * failing test fix --- samtranslator/model/sam_resources.py | 11 ++++++++--- ...with_function_url_config_and_autopublishalias.json | 2 +- ...with_function_url_config_and_autopublishalias.json | 2 +- ...with_function_url_config_and_autopublishalias.json | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index a277aa189..d098c23d3 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -178,7 +178,7 @@ def to_cloudformation(self, **kwargs): if self.FunctionUrlConfig: lambda_url = self._construct_function_url(lambda_function, lambda_alias) resources.append(lambda_url) - url_permission = self._construct_url_permission(lambda_function) + url_permission = self._construct_url_permission(lambda_function, lambda_alias) if url_permission: resources.append(url_permission) @@ -1006,7 +1006,7 @@ def _validate_cors_config_parameter(self, lambda_function): "{} must be of type {}.".format(prop_name, str(prop_type).split("'")[1]), ) - def _construct_url_permission(self, lambda_function): + def _construct_url_permission(self, lambda_function, lambda_alias): """ Construct the lambda permission associated with the function url resource in a case for public access when AuthType is NONE @@ -1016,6 +1016,9 @@ def _construct_url_permission(self, lambda_function): lambda_function : LambdaUrl Lambda Function resource + llambda_alias : LambdaAlias + Lambda Alias resource + Returns ------- LambdaPermission @@ -1030,7 +1033,9 @@ def _construct_url_permission(self, lambda_function): lambda_permission_attributes = self.get_passthrough_resource_attributes() lambda_permission = LambdaPermission(logical_id=logical_id, attributes=lambda_permission_attributes) lambda_permission.Action = "lambda:InvokeFunctionUrl" - lambda_permission.FunctionName = lambda_function.get_runtime_attr("name") + lambda_permission.FunctionName = ( + lambda_alias.get_runtime_attr("arn") if lambda_alias else lambda_function.get_runtime_attr("name") + ) lambda_permission.Principal = "*" lambda_permission.FunctionUrlAuthType = auth_type return lambda_permission diff --git a/tests/translator/output/aws-cn/function_with_function_url_config_and_autopublishalias.json b/tests/translator/output/aws-cn/function_with_function_url_config_and_autopublishalias.json index 5e0d8c2e1..155784e64 100644 --- a/tests/translator/output/aws-cn/function_with_function_url_config_and_autopublishalias.json +++ b/tests/translator/output/aws-cn/function_with_function_url_config_and_autopublishalias.json @@ -85,7 +85,7 @@ "Properties": { "Action": "lambda:InvokeFunctionUrl", "FunctionName": { - "Ref": "MyFunction" + "Ref": "MyFunctionAliaslive" }, "Principal": "*", "FunctionUrlAuthType": "NONE" diff --git a/tests/translator/output/aws-us-gov/function_with_function_url_config_and_autopublishalias.json b/tests/translator/output/aws-us-gov/function_with_function_url_config_and_autopublishalias.json index 9d3a10312..3714b1289 100644 --- a/tests/translator/output/aws-us-gov/function_with_function_url_config_and_autopublishalias.json +++ b/tests/translator/output/aws-us-gov/function_with_function_url_config_and_autopublishalias.json @@ -85,7 +85,7 @@ "Properties": { "Action": "lambda:InvokeFunctionUrl", "FunctionName": { - "Ref": "MyFunction" + "Ref": "MyFunctionAliaslive" }, "Principal": "*", "FunctionUrlAuthType": "NONE" diff --git a/tests/translator/output/function_with_function_url_config_and_autopublishalias.json b/tests/translator/output/function_with_function_url_config_and_autopublishalias.json index 7c547aba9..82d8dd8e1 100644 --- a/tests/translator/output/function_with_function_url_config_and_autopublishalias.json +++ b/tests/translator/output/function_with_function_url_config_and_autopublishalias.json @@ -85,7 +85,7 @@ "Properties": { "Action": "lambda:InvokeFunctionUrl", "FunctionName": { - "Ref": "MyFunction" + "Ref": "MyFunctionAliaslive" }, "Principal": "*", "FunctionUrlAuthType": "NONE"