forked from aws-cloudformation/cfn-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeprecatedRuntimeEnd.py
57 lines (49 loc) · 1.88 KB
/
DeprecatedRuntimeEnd.py
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
47
48
49
50
51
52
53
54
55
56
57
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""
from datetime import datetime
from cfnlint.data import AdditionalSpecs
from cfnlint.helpers import load_resource
from cfnlint.jsonschema import ValidationError
from cfnlint.rules.jsonschema.CfnLintKeyword import CfnLintKeyword
class DeprecatedRuntimeEnd(CfnLintKeyword):
"""Check if EOL Lambda Function Runtimes are used"""
id = "E2531"
shortdesc = "Check if EOL Lambda Function Runtimes are used"
description = (
"Check if an EOL Lambda Runtime is specified and give an error if used. "
)
source_url = (
"https://docs.aws.amazon.com/lambda/latest/dg/runtime-support-policy.html"
)
tags = ["resources", "lambda", "runtime"]
def __init__(self):
"""Init"""
super().__init__(["Resources/AWS::Lambda::Function/Properties/Runtime"])
self.child_rules = {
"W2531": None,
}
self.current_date = datetime.today()
self.deprecated_runtimes = load_resource(
AdditionalSpecs, "LmbdRuntimeLifecycle.json"
)
# pylint: disable=unused-argument
def validate(self, validator, v, runtime, schema):
runtime_data = self.deprecated_runtimes.get(runtime)
if not runtime_data:
return
if (
datetime.strptime(runtime_data["deprecated"], "%Y-%m-%d")
< self.current_date
):
yield ValidationError(
(
f"Deprecated runtime {runtime!r} specified. Updating "
f"disabled since {runtime_data['deprecated']!r}. "
f"Please consider updating to {runtime_data['successor']!r}"
),
rule=self,
)
if self.child_rules["W2531"]:
yield from self.child_rules["W2531"].lambdaruntime(runtime, runtime_data)