From 8bf7894ad1c8d16a881d24329a5b0ffb31a6b46a Mon Sep 17 00:00:00 2001 From: ataylorme Date: Thu, 16 Nov 2023 07:22:37 -0800 Subject: [PATCH 1/2] Add NodeJS 20 support for Lambda [Node.js 20.x runtime is available in AWS Lambda](https://aws.amazon.com/blogs/compute/node-js-20-x-runtime-now-available-in-aws-lambda/) as of 15 November, 2023 --- localstack/aws/api/lambda_/__init__.py | 1 + localstack/services/lambda_/api_utils.py | 3 ++- localstack/services/lambda_/invocation/lambda_models.py | 1 + localstack/services/lambda_/provider.py | 4 ++-- localstack/testing/aws/lambda_utils.py | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/localstack/aws/api/lambda_/__init__.py b/localstack/aws/api/lambda_/__init__.py index bfba229666c67..50be04bd56f41 100644 --- a/localstack/aws/api/lambda_/__init__.py +++ b/localstack/aws/api/lambda_/__init__.py @@ -233,6 +233,7 @@ class Runtime(str): python3_11 = "python3.11" nodejs20_x = "nodejs20.x" provided_al2023 = "provided.al2023" + nodejs20_x = "nodejs20.x" class SnapStartApplyOn(str): diff --git a/localstack/services/lambda_/api_utils.py b/localstack/services/lambda_/api_utils.py index cbee632cf3f4f..1457c7ac91200 100644 --- a/localstack/services/lambda_/api_utils.py +++ b/localstack/services/lambda_/api_utils.py @@ -99,6 +99,7 @@ Runtime.nodejs14_x, Runtime.nodejs16_x, Runtime.nodejs18_x, + Runtime.nodejs20_x, Runtime.python3_7, Runtime.python3_8, Runtime.python3_9, @@ -629,7 +630,7 @@ def validate_layer_runtimes_and_architectures( validations = [] if compatible_runtimes and set(compatible_runtimes).difference(RUNTIMES): - constraint = "Member must satisfy enum value set: [java17, provided, nodejs16.x, nodejs14.x, ruby2.7, python3.10, java11, python3.11, dotnet6, go1.x, nodejs18.x, provided.al2, java8, java8.al2, ruby3.2, python3.7, python3.8, python3.9]" + constraint = "Member must satisfy enum value set: [java17, provided, nodejs16.x, nodejs14.x, ruby2.7, python3.10, java11, python3.11, dotnet6, go1.x, nodejs18.x, provided.al2, java8, java8.al2, ruby3.2, python3.7, python3.8, python3.9, nodejs20.x]" validation_msg = f"Value '[{', '.join([s for s in compatible_runtimes])}]' at 'compatibleRuntimes' failed to satisfy constraint: {constraint}" validations.append(validation_msg) diff --git a/localstack/services/lambda_/invocation/lambda_models.py b/localstack/services/lambda_/invocation/lambda_models.py index f39dc7eafe941..aabda955b00ef 100644 --- a/localstack/services/lambda_/invocation/lambda_models.py +++ b/localstack/services/lambda_/invocation/lambda_models.py @@ -53,6 +53,7 @@ "nodejs14.x": "nodejs:14", "nodejs16.x": "nodejs:16", "nodejs18.x": "nodejs:18", + "nodejs20.x": "nodejs:20", "ruby2.7": "ruby:2.7", "ruby3.2": "ruby:3.2", "java8": "java:8", diff --git a/localstack/services/lambda_/provider.py b/localstack/services/lambda_/provider.py index eaa269f8de357..2e0efcf04fa02 100644 --- a/localstack/services/lambda_/provider.py +++ b/localstack/services/lambda_/provider.py @@ -747,7 +747,7 @@ def create_function( runtime = request.get("Runtime") if package_type == PackageType.Zip and runtime not in IMAGE_MAPPING: raise InvalidParameterValueException( - f"Value {request.get('Runtime')} at 'runtime' failed to satisfy constraint: Member must satisfy enum value set: [java17, provided, nodejs16.x, nodejs14.x, ruby2.7, python3.10, java11, python3.11, dotnet6, go1.x, nodejs18.x, provided.al2, java8, java8.al2, ruby3.2, python3.7, python3.8, python3.9] or be a valid ARN", + f"Value {request.get('Runtime')} at 'runtime' failed to satisfy constraint: Member must satisfy enum value set: [java17, provided, nodejs16.x, nodejs14.x, ruby2.7, python3.10, java11, python3.11, dotnet6, go1.x, nodejs18.x, provided.al2, java8, java8.al2, ruby3.2, python3.7, python3.8, python3.9, nodejs20.x] or be a valid ARN", Type="User", ) if snap_start := request.get("SnapStart"): @@ -944,7 +944,7 @@ def update_function_configuration( if "Runtime" in request: if request["Runtime"] not in IMAGE_MAPPING: raise InvalidParameterValueException( - f"Value {request.get('Runtime')} at 'runtime' failed to satisfy constraint: Member must satisfy enum value set: [java17, provided, nodejs16.x, nodejs14.x, ruby2.7, python3.10, java11, python3.11, dotnet6, go1.x, nodejs18.x, provided.al2, java8, java8.al2, ruby3.2, python3.7, python3.8, python3.9] or be a valid ARN", + f"Value {request.get('Runtime')} at 'runtime' failed to satisfy constraint: Member must satisfy enum value set: [java17, provided, nodejs16.x, nodejs14.x, ruby2.7, python3.10, java11, python3.11, dotnet6, go1.x, nodejs18.x, provided.al2, java8, java8.al2, ruby3.2, python3.7, python3.8, python3.9, nodejs20.x] or be a valid ARN", Type="User", ) replace_kwargs["runtime"] = request["Runtime"] diff --git a/localstack/testing/aws/lambda_utils.py b/localstack/testing/aws/lambda_utils.py index 8a0ea8bece0b3..6a5b3aaea42ca 100644 --- a/localstack/testing/aws/lambda_utils.py +++ b/localstack/testing/aws/lambda_utils.py @@ -41,7 +41,7 @@ Runtime.python3_10, Runtime.python3_11, ], - "nodejs": [Runtime.nodejs14_x, Runtime.nodejs16_x, Runtime.nodejs18_x], + "nodejs": [Runtime.nodejs14_x, Runtime.nodejs16_x, Runtime.nodejs18_x, Runtime.nodejs20_x], "ruby": [Runtime.ruby2_7, Runtime.ruby3_2], "java": [Runtime.java8, Runtime.java8_al2, Runtime.java11, Runtime.java17], "dotnet": [Runtime.dotnet6], From a5dec3830c0319414d7dacc912734825c4e0c947 Mon Sep 17 00:00:00 2001 From: Andrew Taylor Date: Tue, 21 Nov 2023 13:12:38 -0800 Subject: [PATCH 2/2] Remove duplicate nodejs20_x declaration --- localstack/aws/api/lambda_/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/localstack/aws/api/lambda_/__init__.py b/localstack/aws/api/lambda_/__init__.py index 50be04bd56f41..bfba229666c67 100644 --- a/localstack/aws/api/lambda_/__init__.py +++ b/localstack/aws/api/lambda_/__init__.py @@ -233,7 +233,6 @@ class Runtime(str): python3_11 = "python3.11" nodejs20_x = "nodejs20.x" provided_al2023 = "provided.al2023" - nodejs20_x = "nodejs20.x" class SnapStartApplyOn(str):