Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions localstack-core/localstack/services/lambda_/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@
DEPRECATED_RUNTIMES,
DEPRECATED_RUNTIMES_UPGRADES,
RUNTIMES_AGGREGATED,
SNAP_START_SUPPORTED_RUNTIMES,
VALID_RUNTIMES,
)
from localstack.services.lambda_.urlrouter import FunctionUrlRouter
Expand Down Expand Up @@ -686,10 +685,6 @@ def _validate_snapstart(snap_start: SnapStart, runtime: Runtime):
raise ValidationException(
f"1 validation error detected: Value '{apply_on}' at 'snapStart.applyOn' failed to satisfy constraint: Member must satisfy enum value set: [PublishedVersions, None]"
)
if runtime not in SNAP_START_SUPPORTED_RUNTIMES:
raise InvalidParameterValueException(
f"{runtime} is not supported for SnapStart enabled functions.", Type="User"
)

def _validate_layers(self, new_layers: list[str], region: str, account_id: str):
if len(new_layers) > LAMBDA_LAYERS_LIMIT_PER_FUNCTION:
Expand Down
4 changes: 0 additions & 4 deletions localstack-core/localstack/services/lambda_/runtimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@
runtime for runtime_group in RUNTIMES_AGGREGATED.values() for runtime in runtime_group
]

# An unordered list of snapstart-enabled runtimes. Related to snapshots in test_snapstart_exceptions
# https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html
SNAP_START_SUPPORTED_RUNTIMES = [Runtime.java11, Runtime.java17, Runtime.java21]

# An ordered list of all Lambda runtimes considered valid by AWS. Matching snapshots in test_create_lambda_exceptions
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]"
# An ordered list of all Lambda runtimes for layers considered valid by AWS. Matching snapshots in test_layer_exceptions
Expand Down
51 changes: 13 additions & 38 deletions tests/aws/services/lambda_/test_lambda_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from localstack.services.lambda_.runtimes import (
ALL_RUNTIMES,
DEPRECATED_RUNTIMES,
SNAP_START_SUPPORTED_RUNTIMES,
)
from localstack.testing.aws.lambda_utils import (
_await_dynamodb_table_active,
Expand All @@ -59,7 +58,6 @@
from localstack.utils.sync import ShortCircuitWaitException, wait_until
from localstack.utils.testutil import create_lambda_archive
from tests.aws.services.lambda_.test_lambda import (
TEST_LAMBDA_JAVA_WITH_LIB,
TEST_LAMBDA_NODEJS,
TEST_LAMBDA_PYTHON_ECHO,
TEST_LAMBDA_PYTHON_ECHO_ZIP,
Expand Down Expand Up @@ -6565,22 +6563,17 @@ def test_layer_policy_lifecycle(

class TestLambdaSnapStart:
@markers.aws.validated
@pytest.mark.parametrize("runtime", SNAP_START_SUPPORTED_RUNTIMES)
def test_snapstart_lifecycle(self, create_lambda_function, snapshot, aws_client, runtime):
@markers.lambda_runtime_update
@markers.multiruntime(scenario="echo")
def test_snapstart_lifecycle(self, multiruntime_lambda, snapshot, aws_client):
"""Test the API of the SnapStart feature. The optimization behavior is not supported in LocalStack.
Slow (~1-2min) against AWS.
"""
function_name = f"fn-{short_uid()}"
java_jar_with_lib = load_file(TEST_LAMBDA_JAVA_WITH_LIB, mode="rb")
create_response = create_lambda_function(
func_name=function_name,
zip_file=java_jar_with_lib,
runtime=runtime,
handler="cloud.localstack.sample.LambdaHandlerWithLib",
SnapStart={"ApplyOn": "PublishedVersions"},
create_function_response = multiruntime_lambda.create_function(
MemorySize=1024, Timeout=5, SnapStart={"ApplyOn": "PublishedVersions"}
)
snapshot.match("create_function_response", create_response)
aws_client.lambda_.get_waiter("function_active_v2").wait(FunctionName=function_name)
function_name = create_function_response["FunctionName"]
snapshot.match("create_function_response", create_function_response)

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

@markers.aws.validated
@pytest.mark.parametrize("runtime", [Runtime.java21, Runtime.java17])
@markers.lambda_runtime_update
@markers.multiruntime(scenario="echo")
def test_snapstart_update_function_configuration(
self, create_lambda_function, snapshot, aws_client, runtime
self, multiruntime_lambda, snapshot, aws_client
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiruntime_lambda 🚀

):
"""Test enabling SnapStart when updating a function."""
function_name = f"fn-{short_uid()}"
java_jar_with_lib = load_file(TEST_LAMBDA_JAVA_WITH_LIB, mode="rb")
create_response = create_lambda_function(
func_name=function_name,
zip_file=java_jar_with_lib,
runtime=runtime,
handler="cloud.localstack.sample.LambdaHandlerWithLib",
)
snapshot.match("create_function_response", create_response)
create_function_response = multiruntime_lambda.create_function(MemorySize=1024, Timeout=5)
function_name = create_function_response["FunctionName"]
snapshot.match("create_function_response", create_function_response)
aws_client.lambda_.get_waiter("function_active_v2").wait(FunctionName=function_name)

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

with pytest.raises(ClientError) as e:
aws_client.lambda_.create_function(
Expand Down
Loading
Loading