Skip to content
Merged
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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

33 changes: 0 additions & 33 deletions integration/single/test_basic_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,39 +66,6 @@ def test_basic_function_with_architecture(self, file_name, architecture):

self.assertEqual(function_architecture, architecture)

@parameterized.expand(
[
("single/basic_function_with_function_url_config", None),
("single/basic_function_with_function_url_with_autopuplishalias", "live"),
]
)
@skipIf(current_region_does_not_support(["Url"]), "Url is not supported in this testing region")
def test_basic_function_with_url_config(self, file_name, qualifier):
"""
Creates a basic lambda function with Function Url enabled
"""
self.create_and_verify_stack(file_name)

lambda_client = self.client_provider.lambda_client

function_name = self.get_physical_id_by_type("AWS::Lambda::Function")
function_url_config = (
lambda_client.get_function_url_config(FunctionName=function_name, Qualifier=qualifier)
if qualifier
else lambda_client.get_function_url_config(FunctionName=function_name)
)
cors_config = {
"AllowOrigins": ["https://foo.com"],
"AllowMethods": ["POST"],
"AllowCredentials": True,
"AllowHeaders": ["x-Custom-Header"],
"ExposeHeaders": ["x-amzn-header"],
"MaxAge": 10,
}

self.assertEqual(function_url_config["AuthorizationType"], "NONE")
self.assertEqual(function_url_config["Cors"], cors_config)

def test_function_with_deployment_preference_alarms_intrinsic_if(self):
self.create_and_verify_stack("single/function_with_deployment_preference_alarms_intrinsic_if")

Expand Down
9 changes: 0 additions & 9 deletions samtranslator/model/lambda_.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,3 @@ class LambdaLayerVersion(Resource):
}

runtime_attrs = {"name": lambda self: ref(self.logical_id), "arn": lambda self: fnGetAtt(self.logical_id, "Arn")}


class LambdaUrl(Resource):
resource_type = "AWS::Lambda::Url"
property_types = {
"TargetFunctionArn": PropertyType(True, one_of(is_str(), is_type(dict))),
"AuthorizationType": PropertyType(True, is_str()),
"Cors": PropertyType(False, is_type(dict)),
}
84 changes: 0 additions & 84 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
LambdaAlias,
LambdaLayerVersion,
LambdaEventInvokeConfig,
LambdaUrl,
)
from samtranslator.model.types import dict_of, is_str, is_type, list_of, one_of, any_type
from samtranslator.translator import logical_id_generator
Expand Down Expand Up @@ -94,7 +93,6 @@ class SamFunction(SamResourceMacro):
"ImageConfig": PropertyType(False, is_type(dict)),
"CodeSigningConfigArn": PropertyType(False, is_str()),
"Architectures": PropertyType(False, list_of(one_of(is_str(), is_type(dict)))),
"FunctionUrlConfig": PropertyType(False, is_type(dict)),
}
event_resolver = ResourceTypeResolver(
samtranslator.model.eventsources,
Expand Down Expand Up @@ -171,10 +169,6 @@ def to_cloudformation(self, **kwargs):
resources.append(lambda_version)
resources.append(lambda_alias)

if self.FunctionUrlConfig:
lambda_url = self._construct_lambda_url(lambda_function, lambda_alias)
resources.append(lambda_url)

if self.DeploymentPreference:
self._validate_deployment_preference_and_add_update_policy(
kwargs.get("deployment_preference_collection", None),
Expand Down Expand Up @@ -849,84 +843,6 @@ def _validate_deployment_preference_and_add_update_policy(
"UpdatePolicy", deployment_preference_collection.update_policy(self.logical_id).to_dict()
)

def _construct_lambda_url(self, lambda_function, lambda_alias):
"""
This method is used to construct a lambda url resource

Parameters
----------
lambda_function : LambdaFunction
Lambda Function resource
lambda_alias : LambdaAlias
Lambda Alias resource

Returns
-------
LambdaUrl
Lambda Url resource
"""
self._validate_function_url_params(lambda_function)

logical_id = "{id}Url".format(id=lambda_function.logical_id)
lambda_url = LambdaUrl(logical_id=logical_id)

cors = self.FunctionUrlConfig.get("Cors")
if cors:
lambda_url.Cors = cors
lambda_url.AuthorizationType = self.FunctionUrlConfig.get("AuthorizationType")
lambda_url.TargetFunctionArn = (
lambda_alias.get_runtime_attr("arn") if lambda_alias else lambda_function.get_runtime_attr("name")
)
return lambda_url

def _validate_function_url_params(self, lambda_function):
"""
Validate parameters provided to configure Lambda Urls
"""
self._validate_url_auth_type(lambda_function)
self._validate_cors_config_parameter(lambda_function)

def _validate_url_auth_type(self, lambda_function):
if is_intrinsic(self.FunctionUrlConfig):
return

if not self.FunctionUrlConfig.get("AuthorizationType"):
raise InvalidResourceException(
lambda_function.logical_id,
"AuthorizationType is required to configure function property `FunctionUrlConfig`. Please provide either an IAM role name or NONE.",
)

def _validate_cors_config_parameter(self, lambda_function):
if is_intrinsic(self.FunctionUrlConfig):
return

cors_property_data_type = {
"AllowOrigins": list,
"AllowMethods": list,
"AllowCredentials": bool,
"AllowHeaders": list,
"ExposeHeaders": list,
"MaxAge": int,
}

cors = self.FunctionUrlConfig.get("Cors")

if not cors or is_intrinsic(cors):
return

for prop_name, prop_value in cors.items():
if prop_name not in cors_property_data_type:
raise InvalidResourceException(
lambda_function.logical_id,
"{} is not a valid property for configuring Cors.".format(prop_name),
)
prop_type = cors_property_data_type.get(prop_name)
if not is_intrinsic(prop_value) and not isinstance(prop_value, prop_type):
raise InvalidResourceException(
lambda_function.logical_id,
"{} must be of type {}.".format(prop_name, str(prop_type).split("'")[1]),
)


class SamApi(SamResourceMacro):
"""SAM rest API macro."""
Expand Down
10 changes: 2 additions & 8 deletions samtranslator/plugins/globals/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Globals(object):
"FileSystemConfigs",
"CodeSigningConfigArn",
"Architectures",
"FunctionUrlConfig",
],
# Everything except
# DefinitionBody: because its hard to reason about merge of Swagger dictionaries
Expand Down Expand Up @@ -81,8 +80,6 @@ class Globals(object):
],
SamResourceType.SimpleTable.value: ["SSESpecification"],
}
# unreleased_properties *must be* part of supported_properties too
unreleased_properties = {}

def __init__(self, template):
"""
Expand Down Expand Up @@ -198,17 +195,14 @@ def _parse(self, globals_dict):
if not isinstance(properties, dict):
raise InvalidGlobalsSectionException(self._KEYWORD, "Value of ${section} must be a dictionary")

supported = self.supported_properties[resource_type]
supported_displayed = [
prop for prop in supported if prop not in self.unreleased_properties.get(resource_type, [])
]
for key, value in properties.items():
supported = self.supported_properties[resource_type]
if key not in supported:
raise InvalidGlobalsSectionException(
self._KEYWORD,
"'{key}' is not a supported property of '{section}'. "
"Must be one of the following values - {supported}".format(
key=key, section=section_name, supported=supported_displayed
key=key, section=section_name, supported=supported
),
)

Expand Down
Loading