Skip to content

Commit 79452f6

Browse files
authored
fix: Make pass-through properties pass-through in serverless::function (#2924)
1 parent 2c254db commit 79452f6

6 files changed

+19
-124
lines changed

samtranslator/model/sam_resources.py

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ class SamFunction(SamResourceMacro):
9696
resource_type = "AWS::Serverless::Function"
9797
property_types = {
9898
"FunctionName": PropertyType(False, one_of(IS_STR, IS_DICT)),
99-
"Handler": PropertyType(False, IS_STR),
100-
"Runtime": PropertyType(False, IS_STR),
101-
"CodeUri": PropertyType(False, one_of(IS_STR, IS_DICT)),
102-
"ImageUri": PropertyType(False, IS_STR),
103-
"PackageType": PropertyType(False, IS_STR),
104-
"InlineCode": PropertyType(False, one_of(IS_STR, IS_DICT)),
99+
"Handler": PassThroughProperty(False),
100+
"Runtime": PassThroughProperty(False),
101+
"CodeUri": PassThroughProperty(False),
102+
"ImageUri": PassThroughProperty(False),
103+
"PackageType": PassThroughProperty(False),
104+
"InlineCode": PassThroughProperty(False),
105105
"DeadLetterQueue": PropertyType(False, IS_DICT),
106-
"Description": PropertyType(False, IS_STR),
106+
"Description": PassThroughProperty(False),
107107
"MemorySize": PassThroughProperty(False),
108-
"Timeout": PropertyType(False, is_type(int)),
109-
"VpcConfig": PropertyType(False, IS_DICT),
108+
"Timeout": PassThroughProperty(False),
109+
"VpcConfig": PassThroughProperty(False),
110110
"Role": PropertyType(False, IS_STR),
111111
"AssumeRolePolicyDocument": PropertyType(False, IS_DICT),
112112
"Policies": PropertyType(False, one_of(IS_STR, IS_DICT, list_of(one_of(IS_STR, IS_DICT)))),
@@ -116,25 +116,25 @@ class SamFunction(SamResourceMacro):
116116
"Events": PropertyType(False, dict_of(IS_STR, IS_DICT)),
117117
"Tags": PropertyType(False, IS_DICT),
118118
"Tracing": PropertyType(False, one_of(IS_DICT, IS_STR)),
119-
"KmsKeyArn": PropertyType(False, one_of(IS_DICT, IS_STR)),
119+
"KmsKeyArn": PassThroughProperty(False),
120120
"DeploymentPreference": PropertyType(False, IS_DICT),
121-
"ReservedConcurrentExecutions": PropertyType(False, any_type()),
121+
"ReservedConcurrentExecutions": PassThroughProperty(False),
122122
"Layers": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
123123
"EventInvokeConfig": PropertyType(False, IS_DICT),
124-
"EphemeralStorage": PropertyType(False, IS_DICT),
124+
"EphemeralStorage": PassThroughProperty(False),
125125
# Intrinsic functions in value of Alias property are not supported, yet
126126
"AutoPublishAlias": PropertyType(False, one_of(IS_STR)),
127127
"AutoPublishCodeSha256": PropertyType(False, one_of(IS_STR)),
128128
"AutoPublishAliasAllProperties": Property(False, is_type(bool)),
129-
"VersionDescription": PropertyType(False, IS_STR),
130-
"ProvisionedConcurrencyConfig": PropertyType(False, IS_DICT),
131-
"FileSystemConfigs": PropertyType(False, list_of(IS_DICT)),
132-
"ImageConfig": PropertyType(False, IS_DICT),
133-
"CodeSigningConfigArn": PropertyType(False, IS_STR),
134-
"Architectures": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
129+
"VersionDescription": PassThroughProperty(False),
130+
"ProvisionedConcurrencyConfig": PassThroughProperty(False),
131+
"FileSystemConfigs": PassThroughProperty(False),
132+
"ImageConfig": PassThroughProperty(False),
133+
"CodeSigningConfigArn": PassThroughProperty(False),
134+
"Architectures": PassThroughProperty(False),
135135
"SnapStart": PropertyType(False, IS_DICT),
136136
"FunctionUrlConfig": PropertyType(False, IS_DICT),
137-
"RuntimeManagementConfig": PropertyType(False, IS_DICT),
137+
"RuntimeManagementConfig": PassThroughProperty(False),
138138
}
139139

140140
FunctionName: Optional[Intrinsicable[str]]
@@ -543,7 +543,6 @@ def _construct_lambda_function(self) -> LambdaFunction:
543543

544544
lambda_function.RuntimeManagementConfig = self.RuntimeManagementConfig # type: ignore[attr-defined]
545545
self._validate_package_type(lambda_function)
546-
self._validate_architectures(lambda_function)
547546
return lambda_function
548547

549548
def _add_event_invoke_managed_policy(
@@ -666,36 +665,6 @@ def _validate_package_type_image() -> None:
666665
# Call appropriate validation function based on the package type.
667666
return _validate_per_package_type[packagetype]()
668667

669-
def _validate_architectures(self, lambda_function: LambdaFunction) -> None:
670-
"""
671-
Validates Function based on the existence of architecture type
672-
673-
parameters
674-
----------
675-
lambda_function: LambdaFunction
676-
Object of function properties supported on AWS Lambda
677-
678-
Raises
679-
------
680-
InvalidResourceException
681-
Raised when the Architectures property is invalid
682-
"""
683-
684-
architectures = [X86_64] if lambda_function.Architectures is None else lambda_function.Architectures
685-
686-
if is_intrinsic(architectures):
687-
return
688-
689-
if (
690-
not isinstance(architectures, list)
691-
or len(architectures) != 1
692-
or (not is_intrinsic(architectures[0]) and (architectures[0] not in [X86_64, ARM64]))
693-
):
694-
raise InvalidResourceException(
695-
lambda_function.logical_id,
696-
"Architectures needs to be a list with one string, either `{}` or `{}`.".format(X86_64, ARM64),
697-
)
698-
699668
def _validate_dlq(self, dead_letter_queue: Dict[str, Any]) -> None:
700669
"""Validates whether the DeadLetterQueue LogicalId is validation
701670
:raise: InvalidResourceException

tests/model/test_sam_resources.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,6 @@ class TestArchitecture(TestCase):
2525
"managed_policy_map": {"foo": "bar"},
2626
}
2727

28-
@patch("boto3.session.Session.region_name", "ap-southeast-1")
29-
def test_with_unknown_architectures(self):
30-
function = SamFunction("foo")
31-
function.CodeUri = "s3://foobar/foo.zip"
32-
function.Runtime = "foo"
33-
function.Handler = "bar"
34-
invalid_architectures = [["arm"], [1], "arm", 1, {"my": "value"}, True, [], {}]
35-
for architecture in invalid_architectures:
36-
function.Architectures = architecture
37-
with pytest.raises(InvalidResourceException) as e:
38-
function.to_cloudformation(**self.kwargs)
39-
self.assertEqual(
40-
str(e.value.message),
41-
"Resource with id [foo] is invalid. Architectures needs to be a list with one string, either `x86_64` or `arm64`.",
42-
)
43-
44-
@patch("boto3.session.Session.region_name", "ap-southeast-1")
45-
def test_with_multiple_architectures(self):
46-
function = SamFunction("foo")
47-
function.CodeUri = "s3://foobar/foo.zip"
48-
function.Runtime = "foo"
49-
function.Handler = "bar"
50-
function.Architectures = ["arm64", "x86_64"]
51-
52-
with pytest.raises(InvalidResourceException) as e:
53-
function.to_cloudformation(**self.kwargs)
54-
self.assertEqual(
55-
str(e.value.message),
56-
"Resource with id [foo] is invalid. Architectures needs to be a list with one string, either `x86_64` or `arm64`.",
57-
)
58-
5928
@patch("boto3.session.Session.region_name", "ap-southeast-1")
6029
def test_validate_architecture_with_intrinsic(self):
6130
function = SamFunction("foo")

tests/translator/input/error_function_with_multiple_architectures.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/translator/input/error_function_with_unknown_architectures.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/translator/output/error_function_with_multiple_architectures.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/translator/output/error_function_with_unknown_architectures.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)