Skip to content

Commit 59a15cc

Browse files
authored
Validate runtime is string before startswith (#2912)
1 parent 00ee90b commit 59a15cc

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/cfnlint/rules/resources/lmbd/SnapStartEnabled.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self):
2323
self.resource_property_types.append("AWS::Lambda::Function")
2424

2525
def validate(self, runtime, path):
26-
if not runtime:
26+
if not isinstance(runtime, str):
2727
return []
2828

2929
if not (runtime.startswith("java")) and runtime not in ["java8.al2", "java8"]:

src/cfnlint/rules/resources/lmbd/SnapStartSupported.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def match_resource_properties(self, properties, _, path, cfn):
3939
if snap_start.get("ApplyOn") != "PublishedVersions":
4040
continue
4141

42+
# Validate runtime is a string before using startswith
43+
if not isinstance(runtime, str):
44+
continue
45+
4246
if (
4347
runtime
4448
and (not runtime.startswith("java"))

test/fixtures/templates/good/resources/lambda/snapstart-supported.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Parameters:
2+
Runtime:
3+
Type: String
14
Resources:
25
LambdaRole:
36
Type: AWS::IAM::Role
@@ -23,4 +26,19 @@ Resources:
2326
SnapStart:
2427
ApplyOn: PublishedVersions
2528
TracingConfig:
26-
Mode: Active
29+
Mode: Active
30+
31+
FunctionParameter:
32+
Type: AWS::Lambda::Function
33+
Properties:
34+
Handler: index.handler
35+
Role: !GetAtt LambdaRole.Arn
36+
ReservedConcurrentExecutions: 20
37+
Code:
38+
S3Bucket: my-bucket
39+
S3Key: function.zip
40+
Runtime: !Ref Runtime
41+
SnapStart:
42+
ApplyOn: PublishedVersions
43+
TracingConfig:
44+
Mode: Active

0 commit comments

Comments
 (0)