fix lambda layer version compatibility with Python 3.11 by alexrashed · Pull Request #9020 · localstack/localstack · GitHub
Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.
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
4 changes: 4 additions & 0 deletions localstack/services/lambda_/api_utils.py
2 changes: 1 addition & 1 deletion localstack/services/lambda_/invocation/lambda_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

LOG = logging.getLogger(__name__)

# To add support for a new runtime, just add it here with the accompanying image postfix
# To add support for a new runtime, just add it here with the accompanying image postfix and to api_utils.RUNTIMES
IMAGE_MAPPING = {
"python3.7": "python:3.7",
"python3.8": "python:3.8",
Expand Down
4 changes: 2 additions & 2 deletions localstack/services/lambda_/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
from localstack.services.edge import ROUTER
from localstack.services.lambda_ import api_utils
from localstack.services.lambda_ import hooks as lambda_hooks
from localstack.services.lambda_.api_utils import STATEMENT_ID_REGEX
from localstack.services.lambda_.api_utils import ARCHITECTURES, STATEMENT_ID_REGEX
from localstack.services.lambda_.event_source_listeners.event_source_listener import (
EventSourceListener,
)
Expand Down Expand Up @@ -671,7 +671,7 @@ def create_function(
f"1 validation error detected: Value '[{', '.join(architectures)}]' at 'architectures' failed to "
f"satisfy constraint: Member must have length less than or equal to 1",
)
if architectures[0] not in [Architecture.x86_64, Architecture.arm64]:
if architectures[0] not in ARCHITECTURES:
raise ValidationException(
f"1 validation error detected: Value '[{', '.join(architectures)}]' at 'architectures' failed to "
f"satisfy constraint: Member must satisfy constraint: [Member must satisfy enum value set: "
Expand Down
25 changes: 22 additions & 3 deletions tests/aws/services/lambda_/test_lambda_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from localstack.services.lambda_.api_utils import ARCHITECTURES, RUNTIMES
from localstack.testing.pytest import markers

"""
Expand Down Expand Up @@ -4339,9 +4340,27 @@ def snapshot_tags_for_resource(resource_arn: str, snapshot_suffix: str):
@pytest.mark.skipif(condition=is_old_provider(), reason="not supported")
class TestLambdaLayer:
@markers.aws.validated
def test_layer_exceptions(
self, create_lambda_function, snapshot, dummylayer, cleanups, aws_client
):
# AWS only allows a max of 15 compatible runtimes, split runtimes and run two tests
@pytest.mark.parametrize("runtimes", [RUNTIMES[:14], RUNTIMES[14:]])
def test_layer_compatibilities(self, snapshot, dummylayer, cleanups, aws_client, runtimes):
"""Creates a single layer which is compatible with all"""
layer_name = f"testlayer-{short_uid()}"

publish_result = aws_client.lambda_.publish_layer_version(
LayerName=layer_name,
CompatibleRuntimes=runtimes,
Content={"ZipFile": dummylayer},
CompatibleArchitectures=ARCHITECTURES,
)
cleanups.append(
lambda: aws_client.lambda_.delete_layer_version(
LayerName=layer_name, VersionNumber=publish_result["Version"]
)
)
snapshot.match("publish_result", publish_result)

@markers.aws.validated
def test_layer_exceptions(self, snapshot, dummylayer, cleanups, aws_client):
"""
API-level exceptions and edge cases for lambda layers
"""
Expand Down
115 changes: 115 additions & 0 deletions tests/aws/services/lambda_/test_lambda_api.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -13041,5 +13041,120 @@
}
}
}
},
"tests/aws/services/lambda_/test_lambda_api.py::TestLambdaLayer::test_layer_compatibilities": {
"recorded-date": "30-08-2023, 09:57:12",
"recorded-content": {
"publish_result": {
"CompatibleArchitectures": [
"arm64",
"x86_64"
],
"CompatibleRuntimes": [
"nodejs12.x",
"nodejs14.x",
"nodejs16.x",
"nodejs18.x",
"python3.7",
"python3.8",
"python3.9",
"python3.10",
"python3.11",
"ruby2.7",
"ruby3.2",
"java8",
"java8.al2",
"java11"
],
"Content": {
"CodeSha256": "<code-sha256:1>",
"CodeSize": "<code-size>",
"Location": "<layer-location>"
},
"CreatedDate": "date",
"Description": "",
"LayerArn": "arn:aws:lambda:<region>:111111111111:layer:<resource:1>",
"LayerVersionArn": "arn:aws:lambda:<region>:111111111111:layer:<resource:1>:1",
"Version": 1,
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 201
}
}
}
},
"tests/aws/services/lambda_/test_lambda_api.py::TestLambdaLayer::test_layer_compatibilities[runtimes0]": {
"recorded-date": "30-08-2023, 09:59:24",
"recorded-content": {
"publish_result": {
"CompatibleArchitectures": [
"arm64",
"x86_64"
],
"CompatibleRuntimes": [
"nodejs12.x",
"nodejs14.x",
"nodejs16.x",
"nodejs18.x",
"python3.7",
"python3.8",
"python3.9",
"python3.10",
"python3.11",
"ruby2.7",
"ruby3.2",
"java8",
"java8.al2",
"java11"
],
"Content": {
"CodeSha256": "<code-sha256:1>",
"CodeSize": "<code-size>",
"Location": "<layer-location>"
},
"CreatedDate": "date",
"Description": "",
"LayerArn": "arn:aws:lambda:<region>:111111111111:layer:<resource:1>",
"LayerVersionArn": "arn:aws:lambda:<region>:111111111111:layer:<resource:1>:1",
"Version": 1,
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 201
}
}
}
},
"tests/aws/services/lambda_/test_lambda_api.py::TestLambdaLayer::test_layer_compatibilities[runtimes1]": {
"recorded-date": "30-08-2023, 09:59:27",
"recorded-content": {
"publish_result": {
"CompatibleArchitectures": [
"arm64",
"x86_64"
],
"CompatibleRuntimes": [
"java17",
"dotnetcore3.1",
"dotnet6",
"go1.x",
"provided",
"provided.al2"
],
"Content": {
"CodeSha256": "<code-sha256:1>",
"CodeSize": "<code-size>",
"Location": "<layer-location>"
},
"CreatedDate": "date",
"Description": "",
"LayerArn": "arn:aws:lambda:<region>:111111111111:layer:<resource:1>",
"LayerVersionArn": "arn:aws:lambda:<region>:111111111111:layer:<resource:1>:1",
"Version": 1,
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 201
}
}
}
}
}
10 changes: 10 additions & 0 deletions tests/unit/test_lambda.py