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
15 changes: 15 additions & 0 deletions awslambdaric/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)
AWS_LAMBDA_INITIALIZATION_TYPE = "AWS_LAMBDA_INITIALIZATION_TYPE"
INIT_TYPE_SNAP_START = "snap-start"
PREVIEW_RUNTIME_ENVS = {"AWS_Lambda_python3.15"}


def _get_handler(handler):
Expand Down Expand Up @@ -477,6 +478,18 @@ def _setup_logging(log_format, log_level, log_sink):
logger.addHandler(logger_handler)


def _log_preview_runtime_warning():
"""Emit a warning if the runtime version is a preview."""
if os.environ.get("LAMBDA_DISABLE_PREVIEW_WARN", ""):
return

from .lambda_literals import get_lambda_preview_runtime_warning_message

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just out of curiosity. Why don't you import it at top-level? Thats because it's a performance stuff and lazy loading is better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, I'm avoiding the tiny performance hit of the lazy loaded import by returning earlier

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice, that make sense.


execution_env = os.environ.get("AWS_EXECUTION_ENV", "")
if execution_env in PREVIEW_RUNTIME_ENVS:
logging.warning(get_lambda_preview_runtime_warning_message())


def run(handler, lambda_runtime_client):
sys.stdout = Unbuffered(sys.stdout)
sys.stderr = Unbuffered(sys.stderr)
Expand All @@ -488,6 +501,8 @@ def run(handler, lambda_runtime_client):
_setup_logging(_AWS_LAMBDA_LOG_FORMAT, _AWS_LAMBDA_LOG_LEVEL, log_sink)
global _GLOBAL_AWS_REQUEST_ID, _GLOBAL_TENANT_ID

_log_preview_runtime_warning()

request_handler = _get_handler(handler)
except FaultException as e:
error_result = make_error(
Expand Down
1 change: 1 addition & 0 deletions awslambdaric/lambda_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class LambdaConfigProvider:
"AWS_Lambda_python3.12",
"AWS_Lambda_python3.13",
"AWS_Lambda_python3.14",
"AWS_Lambda_python3.15",
}
SOCKET_PATH_ENV = "_LAMBDA_TELEMETRY_LOG_FD_PROVIDER_SOCKET"
AWS_LAMBDA_RUNTIME_API = "AWS_LAMBDA_RUNTIME_API"
Expand Down
23 changes: 23 additions & 0 deletions awslambdaric/lambda_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@

lambda_warning = "LAMBDA_WARNING"

_PREVIEW_DOC_LINK = "https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html"
_PREVIEW_DOC_LINK_CN = "https://docs.amazonaws.cn/lambda/latest/dg/lambda-runtimes.html"


def _get_preview_doc_link():
import os

region = os.environ.get("AWS_REGION", "")
if region.startswith("cn-"):
return _PREVIEW_DOC_LINK_CN
return _PREVIEW_DOC_LINK


# Holds warning message that is emitted when the runtime is a preview version.
def get_lambda_preview_runtime_warning_message():
return str(
f"{lambda_warning}: "
"This is a preview runtime version and should not be used for production workloads. "
"For further information and to provide feedback, see "
f"{_get_preview_doc_link()}\r"
)


# Holds warning message that is emitted when an unhandled exception is raised during function invocation.
lambda_unhandled_exception_warning_message = str(
f"{lambda_warning}: "
Expand Down
1 change: 1 addition & 0 deletions awslambdaric/lambda_runtime_marshaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self):
"AWS_Lambda_python3.12",
"AWS_Lambda_python3.13",
"AWS_Lambda_python3.14",
"AWS_Lambda_python3.15",
}:
super().__init__(use_decimal=False, ensure_ascii=False, allow_nan=True)
else:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_lambda_runtime_marshaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class TestLambdaRuntimeMarshaller(unittest.TestCase):
execution_envs = (
"AWS_Lambda_python3.15",
"AWS_Lambda_python3.14",
"AWS_Lambda_python3.13",
"AWS_Lambda_python3.12",
Expand All @@ -23,6 +24,7 @@ class TestLambdaRuntimeMarshaller(unittest.TestCase):
"AWS_Lambda_python3.12",
"AWS_Lambda_python3.13",
"AWS_Lambda_python3.14",
"AWS_Lambda_python3.15",
}

execution_envs_lambda_marshaller_ensure_ascii_true = tuple(
Expand Down
Loading