Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 8f1df6d

Browse files
committed
Lambda: validate supported runtimes for managed instances
1 parent bdd974d commit 8f1df6d

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
DEPRECATED_RUNTIMES_UPGRADES,
234234
RUNTIMES_AGGREGATED,
235235
SNAP_START_SUPPORTED_RUNTIMES,
236+
VALID_MANAGED_INSTANCE_RUNTIMES,
236237
VALID_RUNTIMES,
237238
)
238239
from localstack.services.lambda_.urlrouter import FunctionUrlRouter
@@ -1076,6 +1077,7 @@ def create_function(
10761077
if "CapacityProviderConfig" in request:
10771078
capacity_provider_config = request["CapacityProviderConfig"]
10781079
self._validate_capacity_provider_config(capacity_provider_config, context)
1080+
self._validate_managed_instances_runtime(runtime)
10791081

10801082
default_config = CapacityProviderConfig(
10811083
LambdaManagedInstancesCapacityProviderConfig=LambdaManagedInstancesCapacityProviderConfig(
@@ -1252,6 +1254,12 @@ def _validate_runtime(self, package_type, runtime):
12521254
Type="User",
12531255
)
12541256

1257+
def _validate_managed_instances_runtime(self, runtime):
1258+
if runtime not in VALID_MANAGED_INSTANCE_RUNTIMES:
1259+
raise InvalidParameterValueException(
1260+
f"Runtime Enum {runtime} does not support specified feature: Lambda Managed Instances"
1261+
)
1262+
12551263
def _check_for_recomended_migration_target(self, deprecated_runtime):
12561264
# AWS offers recommended runtime for migration for "newly" deprecated runtimes
12571265
# in order to preserve parity with error messages we need the code bellow

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,16 @@
176176
VALID_RUNTIMES: str = "[nodejs20.x, python3.14, provided.al2023, python3.12, python3.13, nodejs24.x, nodejs22.x, java25, python3.10, python3.11, java21, ruby3.3, ruby3.4, ruby3.2, python3.8, python3.9, java17, nodejs16.x, dotnet10, dotnet8, java11, dotnet6, nodejs18.x, provided.al2, java8.al2]"
177177
# An ordered list of all Lambda runtimes for layers considered valid by AWS. Matching snapshots in test_layer_exceptions
178178
VALID_LAYER_RUNTIMES: str = "[ruby3.5, ruby2.6, dotnetcore1.0, python3.7, nodejs8.10, nasa, ruby2.7, python2.7-greengrass, dotnetcore2.0, python3.8, java21, dotnet6, dotnetcore2.1, python3.9, java11, nodejs6.10, provided, dotnetcore3.1, dotnet8, java25, java17, nodejs, nodejs4.3, java8.al2, go1.x, dotnet10, nodejs20.x, go1.9, byol, nodejs10.x, provided.al2023, nodejs22.x, python3.10, java8, nodejs12.x, python3.11, nodejs24.x, nodejs8.x, python3.12, nodejs14.x, nodejs8.9, nodejs26.x, python3.13, python3.14, nodejs16.x, python3.15, provided.al2, nodejs4.3-edge, nodejs18.x, ruby3.2, python3.4, ruby3.3, ruby3.4, ruby2.5, python3.6, python2.7]"
179+
180+
181+
VALID_MANAGED_INSTANCE_RUNTIMES = [
182+
Runtime.nodejs24_x,
183+
Runtime.nodejs22_x,
184+
Runtime.python3_14,
185+
Runtime.python3_13,
186+
Runtime.java25,
187+
Runtime.java21,
188+
Runtime.dotnet10,
189+
Runtime.dotnet8,
190+
Runtime.provided_al2023,
191+
]

localstack-core/localstack/testing/aws/lambda_utils.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
from localstack.utils.files import load_file
1515
from localstack.utils.platform import Arch, get_arch
1616
from localstack.utils.strings import short_uid
17-
from localstack.utils.sync import ShortCircuitWaitException, retry
17+
from localstack.utils.sync import ShortCircuitWaitException, retry, wait_until
1818
from localstack.utils.testutil import get_lambda_log_events
1919

2020
if TYPE_CHECKING:
2121
from mypy_boto3_lambda import LambdaClient
2222
from mypy_boto3_lambda.literals import ArchitectureType, PackageTypeType, RuntimeType
2323
from mypy_boto3_lambda.type_defs import (
24+
CapacityProviderConfigTypeDef,
2425
DeadLetterConfigTypeDef,
2526
EnvironmentTypeDef,
2627
EphemeralStorageTypeDef,
@@ -200,6 +201,7 @@ def create_function(
200201
CodeSigningConfigArn: str | None = None,
201202
Architectures: Sequence["ArchitectureType"] | None = None,
202203
EphemeralStorage: Optional["EphemeralStorageTypeDef"] = None,
204+
CapacityProviderConfig: Optional["CapacityProviderConfigTypeDef"] = None,
203205
) -> "FunctionConfigurationResponseMetadataTypeDef": ...
204206

205207
def create_function(self, **kwargs):
@@ -216,9 +218,22 @@ def _create_function():
216218
# localstack should normally not require the retries and will just continue here
217219
result = retry(_create_function, retries=3, sleep=4)
218220
self.function_names.append(result["FunctionArn"])
219-
self.lambda_client.get_waiter("function_active_v2").wait(
220-
FunctionName=kwargs.get("FunctionName")
221-
)
221+
222+
def _is_not_pending():
223+
try:
224+
result = (
225+
self.lambda_client.get_function(FunctionName=kwargs.get("FunctionName"))[
226+
"Configuration"
227+
]["State"]
228+
!= "Pending"
229+
)
230+
LOG.debug("lambda state result: result=%s", result)
231+
return result
232+
except Exception as e:
233+
LOG.error(e)
234+
raise
235+
236+
wait_until(_is_not_pending)
222237

223238
return result
224239

0 commit comments

Comments
 (0)