fix(lambda): pass LoggingConfig log format and level to the runtime (#6775)

* fix(lambda): pass LoggingConfig log format and level to the runtime

A function with LogFormat=JSON logged text: neither launcher set AWS_LAMBDA_LOG_FORMAT or AWS_LAMBDA_LOG_LEVEL, which the runtime interface clients read. Both launchers now pass them, and a JSON function without an ApplicationLogLevel gets INFO, the level the API reports, through one default shared with the response.

Closes #6774

* docs(lambda): note the log format and level the runtime receives

* refactor(lambda): build the runtime environment in one place for both launchers

ContainerLauncher and KubernetesPodLauncher wrote the same AWS_LAMBDA_* lines, the LoggingConfig ones included. LambdaRuntimeEnv.of now builds them once.
This commit is contained in:
Francisco Javier Barón authored and GitHub committed 2026-10-28 09:04:14 -04:00
1 parent 119b7e9580
commit 481b7f8d6d
8 files changed
+98 -23

No files matched your search

@@ -333,6 +333,30 @@ class ContainerLauncherTest {
.filter(value -> value.startsWith("AWS_LAMBDA_FUNCTION_VERSION=")).toList());
}
@ParameterizedTest
@CsvSource({"JSON, DEBUG, DEBUG", "JSON, , INFO", "Text, , "})
void launchPassesTheLoggingConfigToTheRuntime(String logFormat, String level, String runtimeLevel) {
LambdaFunction fn = new LambdaFunction();
fn.setFunctionName("logging-config-fn");
fn.setHotReloadHostPath("/home/ci/code");
fn.setRuntime("python3.13");
fn.setHandler("fn.handler");
fn.setLogFormat(logFormat);
fn.setApplicationLogLevel(level);
launcher.launch(fn);
List<String> expected = new ArrayList<>(List.of("AWS_LAMBDA_LOG_FORMAT=" + logFormat));
if (runtimeLevel != null) {
expected.add("AWS_LAMBDA_LOG_LEVEL=" + runtimeLevel);
}
assertEquals(expected,
captureRealContainerSpec().env().stream()
.filter(value -> value.startsWith("AWS_LAMBDA_LOG_FORMAT=")
|| value.startsWith("AWS_LAMBDA_LOG_LEVEL="))
.toList());
}
@Test
void launchFunction_hotReloadMountsTheHostDirectoryReadOnlyAtVarTask() {
LambdaFunction fn = new LambdaFunction();
@@ -247,6 +247,23 @@ class KubernetesPodLauncherTest {
verify(runtimeApiServer).setFunctionMetadata("my-fn", version, "index.handler", "000000000000");
}
@Test
void launchPassesTheLoggingConfigToTheRuntime() {
markPodPhaseInBackground("floci-lambda-my-fn-", "Running");
LambdaFunction fn = function();
fn.setLogFormat("JSON");
fn.setApplicationLogLevel("DEBUG");
ContainerHandle handle = launcher.launch(fn);
Pod pod = client.pods().inNamespace("default").withName(handle.getContainerId()).get();
assertThat(pod.getSpec().getContainers().getFirst().getEnv())
.filteredOn(variable -> "AWS_LAMBDA_LOG_FORMAT".equals(variable.getName())
|| "AWS_LAMBDA_LOG_LEVEL".equals(variable.getName()))
.extracting(EnvVar::getValue)
.containsExactly("JSON", "DEBUG");
}
@Test
void launchPassesTheFunctionsOwningAccountIntoTheBaselineAwsEnv() {
// A pod-launched Lambda is subject to the same placeholder-credential bug as a