Skip to content

Commit f6f83d2

Browse files
authored
Allow usage of additional runtimes with the Lambda SnapStart feature enabled (#12006)
1 parent 37a56a5 commit f6f83d2

File tree

5 files changed

+4419
-406
lines changed

5 files changed

+4419
-406
lines changed

localstack-core/localstack/services/lambda_/provider.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@
209209
DEPRECATED_RUNTIMES,
210210
DEPRECATED_RUNTIMES_UPGRADES,
211211
RUNTIMES_AGGREGATED,
212-
SNAP_START_SUPPORTED_RUNTIMES,
213212
VALID_RUNTIMES,
214213
)
215214
from localstack.services.lambda_.urlrouter import FunctionUrlRouter
@@ -686,10 +685,6 @@ def _validate_snapstart(snap_start: SnapStart, runtime: Runtime):
686685
raise ValidationException(
687686
f"1 validation error detected: Value '{apply_on}' at 'snapStart.applyOn' failed to satisfy constraint: Member must satisfy enum value set: [PublishedVersions, None]"
688687
)
689-
if runtime not in SNAP_START_SUPPORTED_RUNTIMES:
690-
raise InvalidParameterValueException(
691-
f"{runtime} is not supported for SnapStart enabled functions.", Type="User"
692-
)
693688

694689
def _validate_layers(self, new_layers: list[str], region: str, account_id: str):
695690
if len(new_layers) > LAMBDA_LAYERS_LIMIT_PER_FUNCTION:

localstack-core/localstack/services/lambda_/runtimes.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@
149149
runtime for runtime_group in RUNTIMES_AGGREGATED.values() for runtime in runtime_group
150150
]
151151

152-
# An unordered list of snapstart-enabled runtimes. Related to snapshots in test_snapstart_exceptions
153-
# https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html
154-
SNAP_START_SUPPORTED_RUNTIMES = [Runtime.java11, Runtime.java17, Runtime.java21]
155-
156152
# An ordered list of all Lambda runtimes considered valid by AWS. Matching snapshots in test_create_lambda_exceptions
157153
VALID_RUNTIMES: str = "[nodejs20.x, provided.al2023, python3.12, python3.13, nodejs22.x, java17, nodejs16.x, dotnet8, python3.10, java11, python3.11, dotnet6, java21, nodejs18.x, provided.al2, ruby3.3, java8.al2, ruby3.2, python3.8, python3.9]"
158154
# An ordered list of all Lambda runtimes for layers considered valid by AWS. Matching snapshots in test_layer_exceptions

tests/aws/services/lambda_/test_lambda_api.py

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
from localstack.services.lambda_.runtimes import (
3737
ALL_RUNTIMES,
3838
DEPRECATED_RUNTIMES,
39-
SNAP_START_SUPPORTED_RUNTIMES,
4039
)
4140
from localstack.testing.aws.lambda_utils import (
4241
_await_dynamodb_table_active,
@@ -59,7 +58,6 @@
5958
from localstack.utils.sync import ShortCircuitWaitException, wait_until
6059
from localstack.utils.testutil import create_lambda_archive
6160
from tests.aws.services.lambda_.test_lambda import (
62-
TEST_LAMBDA_JAVA_WITH_LIB,
6361
TEST_LAMBDA_NODEJS,
6462
TEST_LAMBDA_PYTHON_ECHO,
6563
TEST_LAMBDA_PYTHON_ECHO_ZIP,
@@ -6565,22 +6563,17 @@ def test_layer_policy_lifecycle(
65656563

65666564
class TestLambdaSnapStart:
65676565
@markers.aws.validated
6568-
@pytest.mark.parametrize("runtime", SNAP_START_SUPPORTED_RUNTIMES)
6569-
def test_snapstart_lifecycle(self, create_lambda_function, snapshot, aws_client, runtime):
6566+
@markers.lambda_runtime_update
6567+
@markers.multiruntime(scenario="echo")
6568+
def test_snapstart_lifecycle(self, multiruntime_lambda, snapshot, aws_client):
65706569
"""Test the API of the SnapStart feature. The optimization behavior is not supported in LocalStack.
65716570
Slow (~1-2min) against AWS.
65726571
"""
6573-
function_name = f"fn-{short_uid()}"
6574-
java_jar_with_lib = load_file(TEST_LAMBDA_JAVA_WITH_LIB, mode="rb")
6575-
create_response = create_lambda_function(
6576-
func_name=function_name,
6577-
zip_file=java_jar_with_lib,
6578-
runtime=runtime,
6579-
handler="cloud.localstack.sample.LambdaHandlerWithLib",
6580-
SnapStart={"ApplyOn": "PublishedVersions"},
6572+
create_function_response = multiruntime_lambda.create_function(
6573+
MemorySize=1024, Timeout=5, SnapStart={"ApplyOn": "PublishedVersions"}
65816574
)
6582-
snapshot.match("create_function_response", create_response)
6583-
aws_client.lambda_.get_waiter("function_active_v2").wait(FunctionName=function_name)
6575+
function_name = create_function_response["FunctionName"]
6576+
snapshot.match("create_function_response", create_function_response)
65846577

65856578
publish_response = aws_client.lambda_.publish_version(
65866579
FunctionName=function_name, Description="version1"
@@ -6599,20 +6592,15 @@ def test_snapstart_lifecycle(self, create_lambda_function, snapshot, aws_client,
65996592
snapshot.match("get_function_response_version_1", get_function_response)
66006593

66016594
@markers.aws.validated
6602-
@pytest.mark.parametrize("runtime", [Runtime.java21, Runtime.java17])
6595+
@markers.lambda_runtime_update
6596+
@markers.multiruntime(scenario="echo")
66036597
def test_snapstart_update_function_configuration(
6604-
self, create_lambda_function, snapshot, aws_client, runtime
6598+
self, multiruntime_lambda, snapshot, aws_client
66056599
):
66066600
"""Test enabling SnapStart when updating a function."""
6607-
function_name = f"fn-{short_uid()}"
6608-
java_jar_with_lib = load_file(TEST_LAMBDA_JAVA_WITH_LIB, mode="rb")
6609-
create_response = create_lambda_function(
6610-
func_name=function_name,
6611-
zip_file=java_jar_with_lib,
6612-
runtime=runtime,
6613-
handler="cloud.localstack.sample.LambdaHandlerWithLib",
6614-
)
6615-
snapshot.match("create_function_response", create_response)
6601+
create_function_response = multiruntime_lambda.create_function(MemorySize=1024, Timeout=5)
6602+
function_name = create_function_response["FunctionName"]
6603+
snapshot.match("create_function_response", create_function_response)
66166604
aws_client.lambda_.get_waiter("function_active_v2").wait(FunctionName=function_name)
66176605

66186606
update_function_response = aws_client.lambda_.update_function_configuration(
@@ -6625,19 +6613,6 @@ def test_snapstart_update_function_configuration(
66256613
def test_snapstart_exceptions(self, lambda_su_role, snapshot, aws_client):
66266614
function_name = f"invalid-function-{short_uid()}"
66276615
zip_file_bytes = create_lambda_archive(load_file(TEST_LAMBDA_PYTHON_ECHO), get_content=True)
6628-
# Test unsupported runtime
6629-
# Only supports java11 (2023-02-15): https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html
6630-
with pytest.raises(ClientError) as e:
6631-
aws_client.lambda_.create_function(
6632-
FunctionName=function_name,
6633-
Handler="index.handler",
6634-
Code={"ZipFile": zip_file_bytes},
6635-
PackageType="Zip",
6636-
Role=lambda_su_role,
6637-
Runtime=Runtime.python3_12,
6638-
SnapStart={"ApplyOn": "PublishedVersions"},
6639-
)
6640-
snapshot.match("create_function_unsupported_snapstart_runtime", e.value.response)
66416616

66426617
with pytest.raises(ClientError) as e:
66436618
aws_client.lambda_.create_function(

0 commit comments

Comments
 (0)