Skip to content

Commit 3c864c8

Browse files
authored
Merge pull request #209 from aws/stefantm/preview-warning
Add preview warning for Python 3.15
2 parents 296b39f + 2068ac0 commit 3c864c8

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

awslambdaric/bootstrap.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
)
3434
AWS_LAMBDA_INITIALIZATION_TYPE = "AWS_LAMBDA_INITIALIZATION_TYPE"
3535
INIT_TYPE_SNAP_START = "snap-start"
36+
PREVIEW_RUNTIME_ENVS = {"AWS_Lambda_python3.15"}
3637

3738

3839
def _get_handler(handler):
@@ -477,6 +478,18 @@ def _setup_logging(log_format, log_level, log_sink):
477478
logger.addHandler(logger_handler)
478479

479480

481+
def _log_preview_runtime_warning():
482+
"""Emit a warning if the runtime version is a preview."""
483+
if os.environ.get("LAMBDA_DISABLE_PREVIEW_WARN", ""):
484+
return
485+
486+
from .lambda_literals import get_lambda_preview_runtime_warning_message
487+
488+
execution_env = os.environ.get("AWS_EXECUTION_ENV", "")
489+
if execution_env in PREVIEW_RUNTIME_ENVS:
490+
logging.warning(get_lambda_preview_runtime_warning_message())
491+
492+
480493
def run(handler, lambda_runtime_client):
481494
sys.stdout = Unbuffered(sys.stdout)
482495
sys.stderr = Unbuffered(sys.stderr)
@@ -488,6 +501,8 @@ def run(handler, lambda_runtime_client):
488501
_setup_logging(_AWS_LAMBDA_LOG_FORMAT, _AWS_LAMBDA_LOG_LEVEL, log_sink)
489502
global _GLOBAL_AWS_REQUEST_ID, _GLOBAL_TENANT_ID
490503

504+
_log_preview_runtime_warning()
505+
491506
request_handler = _get_handler(handler)
492507
except FaultException as e:
493508
error_result = make_error(

awslambdaric/lambda_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class LambdaConfigProvider:
1010
"AWS_Lambda_python3.12",
1111
"AWS_Lambda_python3.13",
1212
"AWS_Lambda_python3.14",
13+
"AWS_Lambda_python3.15",
1314
}
1415
SOCKET_PATH_ENV = "_LAMBDA_TELEMETRY_LOG_FD_PROVIDER_SOCKET"
1516
AWS_LAMBDA_RUNTIME_API = "AWS_LAMBDA_RUNTIME_API"

awslambdaric/lambda_literals.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@
44

55
lambda_warning = "LAMBDA_WARNING"
66

7+
_PREVIEW_DOC_LINK = "https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html"
8+
_PREVIEW_DOC_LINK_CN = "https://docs.amazonaws.cn/lambda/latest/dg/lambda-runtimes.html"
9+
10+
11+
def _get_preview_doc_link():
12+
import os
13+
14+
region = os.environ.get("AWS_REGION", "")
15+
if region.startswith("cn-"):
16+
return _PREVIEW_DOC_LINK_CN
17+
return _PREVIEW_DOC_LINK
18+
19+
20+
# Holds warning message that is emitted when the runtime is a preview version.
21+
def get_lambda_preview_runtime_warning_message():
22+
return str(
23+
f"{lambda_warning}: "
24+
"This is a preview runtime version and should not be used for production workloads. "
25+
"For further information and to provide feedback, see "
26+
f"{_get_preview_doc_link()}\r"
27+
)
28+
29+
730
# Holds warning message that is emitted when an unhandled exception is raised during function invocation.
831
lambda_unhandled_exception_warning_message = str(
932
f"{lambda_warning}: "

awslambdaric/lambda_runtime_marshaller.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(self):
1919
"AWS_Lambda_python3.12",
2020
"AWS_Lambda_python3.13",
2121
"AWS_Lambda_python3.14",
22+
"AWS_Lambda_python3.15",
2223
}:
2324
super().__init__(use_decimal=False, ensure_ascii=False, allow_nan=True)
2425
else:

tests/test_lambda_runtime_marshaller.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class TestLambdaRuntimeMarshaller(unittest.TestCase):
1313
execution_envs = (
14+
"AWS_Lambda_python3.15",
1415
"AWS_Lambda_python3.14",
1516
"AWS_Lambda_python3.13",
1617
"AWS_Lambda_python3.12",
@@ -23,6 +24,7 @@ class TestLambdaRuntimeMarshaller(unittest.TestCase):
2324
"AWS_Lambda_python3.12",
2425
"AWS_Lambda_python3.13",
2526
"AWS_Lambda_python3.14",
27+
"AWS_Lambda_python3.15",
2628
}
2729

2830
execution_envs_lambda_marshaller_ensure_ascii_true = tuple(

0 commit comments

Comments
 (0)