Skip to content

Commit 027ffc0

Browse files
authored
fix: add check for CodeUri property type (#3531)
1 parent e17dc8f commit 027ffc0

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

samtranslator/model/s3_utils/uri_parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def construct_s3_location_object(
8585

8686
s3_pointer = location_uri
8787

88-
else:
88+
elif isinstance(location_uri, str):
8989
# SSM Pattern found here https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html
9090
ssm_pattern = r"{{resolve:(ssm|ssm-secure|secretsmanager):[a-zA-Z0-9_.\-/]+(:\d+)?}}"
9191
match = search(ssm_pattern, location_uri)
@@ -107,6 +107,8 @@ def construct_s3_location_object(
107107
"parameter.",
108108
)
109109
s3_pointer = _s3_pointer
110+
else:
111+
raise InvalidResourceException(logical_id, f"'{property_name}' must be of type dict or string.")
110112

111113
code = {"S3Bucket": s3_pointer["Bucket"], "S3Key": s3_pointer["Key"]}
112114
if "Version" in s3_pointer:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Resources:
2+
Function:
3+
Type: AWS::Serverless::Function
4+
Properties:
5+
CodeUri: []
6+
Runtime: python2.7
7+
Handler: hello.handler
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Resource with id [Function] is invalid. ",
6+
"'CodeUri' must be of type dict or string."
7+
],
8+
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. 'CodeUri' must be of type dict or string.",
9+
"errors": [
10+
{
11+
"errorMessage": "Resource with id [Function] is invalid. 'CodeUri' must be of type dict or string."
12+
}
13+
]
14+
}

0 commit comments

Comments
 (0)