Skip to content

Commit

Permalink
SnapStart is okay with new python dotnet (#3890)
Browse files Browse the repository at this point in the history
* SnapStart is okay with new python dotnet
  • Loading branch information
kddejong authored Dec 30, 2024
1 parent 700563c commit 8f5129d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 7 deletions.
26 changes: 21 additions & 5 deletions src/cfnlint/rules/resources/lmbd/SnapStartSupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ def __init__(self):
"sa-east-1",
]

def _is_runtime_valid(self, runtime: str) -> bool:
if not any(runtime.startswith(r) for r in ["python", "java", "dotnet"]):
return False

if runtime.startswith("dotnetcore"):
return False

return runtime not in [
"dotnet5.0",
"dotnet6",
"dotnet7",
"java8.al2",
"java8",
"python3.10",
"python3.11",
"python3.7",
"python3.8",
"python3.9",
]

def validate(
self, validator: Validator, _, instance: Any, schema: dict[str, Any]
) -> ValidationResult:
Expand Down Expand Up @@ -94,11 +114,7 @@ def validate(
if not isinstance(runtime, str):
continue

if (
runtime
and (not runtime.startswith("java"))
and runtime not in ["java8.al2", "java8"]
):
if not self._is_runtime_valid(runtime):
yield ValidationError(
f"{runtime!r} is not supported for 'SnapStart' enabled functions",
path=deque(["SnapStart", "ApplyOn"]),
Expand Down
87 changes: 85 additions & 2 deletions test/unit/rules/resources/lmbd/test_snapstart_supported.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,90 @@ def rule():
],
),
(
"SnapStart not enabled on non java runtime",
"SnapStart enabled for python3.12 error",
{
"Runtime": "python3.12",
"SnapStart": {
"ApplyOn": "PublishedVersions",
},
},
["us-east-1"],
True,
False,
[],
),
(
"SnapStart enabled for dotnet",
{
"Runtime": "dotnet8",
"SnapStart": {
"ApplyOn": "PublishedVersions",
},
},
["us-east-1"],
True,
False,
[],
),
(
"SnapStart enabled for go that isn't supported",
{
"Runtime": "go1.x",
"SnapStart": {
"ApplyOn": "PublishedVersions",
},
},
["us-east-1"],
True,
False,
[
ValidationError(
"'go1.x' is not supported for 'SnapStart' enabled functions",
path=deque(["SnapStart", "ApplyOn"]),
)
],
),
(
"SnapStart enabled for dotnet version that isn't supported",
{
"Runtime": "dotnet5.0",
"SnapStart": {
"ApplyOn": "PublishedVersions",
},
},
["us-east-1"],
True,
False,
[
ValidationError(
"'dotnet5.0' is not supported for 'SnapStart' enabled functions",
path=deque(["SnapStart", "ApplyOn"]),
)
],
),
(
"SnapStart enabled for dotnetcore version that isn't supported",
{
"Runtime": "dotnetcore2.1",
"SnapStart": {
"ApplyOn": "PublishedVersions",
},
},
["us-east-1"],
True,
False,
[
ValidationError(
(
"'dotnetcore2.1' is not supported for "
"'SnapStart' enabled functions"
),
path=deque(["SnapStart", "ApplyOn"]),
)
],
),
(
"SnapStart not enabled on python non supported runtime",
{
"Runtime": "python3.11",
},
Expand All @@ -76,7 +159,7 @@ def rule():
[],
),
(
"SnapStart not enabled on java runtime in a bad region",
"SnapStart not enabled on python runtime in a bad region",
{
"Runtime": "python3.11",
},
Expand Down

0 comments on commit 8f5129d

Please sign in to comment.