forked from aws-cloudformation/cfn-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnapStart.py
More file actions
46 lines (37 loc) · 1.4 KB
/
SnapStart.py
File metadata and controls
46 lines (37 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""
from cfnlint.jsonschema import ValidationError
from cfnlint.rules.jsonschema.CfnLintKeyword import CfnLintKeyword
class SnapStart(CfnLintKeyword):
"""Check if Lambda SnapStart is properly configured"""
id = "W2530"
shortdesc = "Validate that SnapStart is properly configured"
description = (
"To properly leverage SnapStart, you must configure both the lambda function "
"and attach a Lambda version resource"
)
source_url = "https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html"
tags = ["resources", "lambda"]
def __init__(self):
super().__init__(
["Resources/AWS::Lambda::Function/Properties/SnapStart/ApplyOn"]
)
def validate(self, validator, _, instance, schema):
if not validator.is_type(instance, "string"):
return
if instance != "PublishedVersions":
return
resource_name = validator.context.path[1]
lambda_version_type = "AWS::Lambda::Version"
if list(
validator.cfn.get_resource_children(resource_name, [lambda_version_type])
):
return
yield ValidationError(
(
f"'SnapStart' is enabled but an {lambda_version_type!r} "
"resource is not attached"
),
)