fix(lambda): refuse a log level under Text as Lambda does (#5920)

Floci accepted ApplicationLogLevel and SystemLogLevel under Text and
dropped them, which a test pinned and the docs described as Floci's own
call rather than probed behaviour. Measured on Lambda (eu-west-1,
2026-10-18): CreateFunction and UpdateFunctionConfiguration refuse either
level under Text, whether LogFormat names Text or is left to that
default, with InvalidParameterValueException "LogLevel is not supported
when LogFormat is set to "Text". Remove LogLevel from your request or
change the LogFormat to "JSON" and try again." In a stack, a valid level
under Text passes the template's validation and fails the resource with
Lambda's message. Floci now refuses it in validateLoggingConfig, so the
API and the CloudFormation update check, which validates through
loggingSettings, both do; and its enum errors list the levels in Lambda's
order: [FATAL, TRACE, WARN, ERROR, INFO, DEBUG] and [WARN, INFO, DEBUG].

The default format is worked out in one place, logFormat, for the
validation and for loggingSettings.

Tests: a level under Text refused on create and on update through the API
(LambdaVpcSnapStartLoggingIntegrationTest, replacing the test that pinned
the old behaviour) and through the SDK (LambdaFunctionConfigTest), by
loggingSettings (LambdaServiceTest), and by a stack update
(CloudFormationLambdaLoggingConfigIntegrationTest); the enum messages'
order. They fail on main.
This commit is contained in:
Alessandro Lattao authored and GitHub committed 2026-10-18 08:10:40 -04:00
1 parent 5a4413d63a
commit d425e2d884
6 files changed
+163 -48

No files matched your search

@@ -328,4 +328,35 @@ class LambdaFunctionConfigTest {
}
}
}
@Test
@Order(8)
@DisplayName("a log level under Text is refused on create and on update, as Lambda refuses it")
void logLevelUnderTextIsRefused() {
// Measured on Lambda (eu-west-1, 2026-10-18), with the format named or left to its default.
String refused = "LogLevel is not supported when LogFormat is set to \"Text\". Remove LogLevel from your "
+ "request or change the LogFormat to \"JSON\" and try again.";
assertThatThrownBy(() -> lambda.createFunction(CreateFunctionRequest.builder()
.functionName(TestFixtures.uniqueName("fn-text-level"))
.runtime(Runtime.NODEJS20_X)
.role(ROLE)
.handler("index.handler")
.code(FunctionCode.builder()
.zipFile(SdkBytes.fromByteArray(LambdaUtils.minimalZip()))
.build())
.loggingConfig(LoggingConfig.builder()
.logFormat(LogFormat.TEXT)
.applicationLogLevel(ApplicationLogLevel.WARN)
.build())
.build()))
.isInstanceOf(InvalidParameterValueException.class)
.hasMessageContaining(refused);
assertThatThrownBy(() -> lambda.updateFunctionConfiguration(UpdateFunctionConfigurationRequest.builder()
.functionName(FN)
.loggingConfig(LoggingConfig.builder().systemLogLevel(SystemLogLevel.WARN).build())
.build()))
.isInstanceOf(InvalidParameterValueException.class)
.hasMessageContaining(refused);
}
}
+5 -6
View File
@@ -830,12 +830,11 @@ without `DurableConfig` cannot gain one. CloudFormation and Terraform (`durable_
the function to add or remove it. See Durable Functions for the execution itself.
`LogGroup` is validated against AWS's documented constraint: 1-512 characters matching
`[.\-_/#A-Za-z0-9]+`. `ApplicationLogLevel` and `SystemLogLevel` are accepted with any
`LogFormat` but are only ever stored — and therefore only ever returned — when the
resolved format is `JSON`; supplying them with `LogFormat=Text` is not an error, it is
simply a no-op. That is Floci's own call rather than probed AWS behaviour: it keeps the
request path consistent with Floci's response shape, which never surfaces the levels for
Text.
`[.\-_/#A-Za-z0-9]+`. `ApplicationLogLevel` and `SystemLogLevel` belong to `LogFormat=JSON`:
a log level under Text, whether `LogFormat` names Text or is left to that default, is refused
on create and on update with `InvalidParameterValueException` ("LogLevel is not supported when
LogFormat is set to "Text". Remove LogLevel from your request or change the LogFormat to
"JSON" and try again."), as Lambda refuses it (measured in eu-west-1, 2026-10-18).
`VpcConfig` is omitted entirely while the function is not attached to a VPC.
Subnets that EC2 does not know about are still accepted and returned; only `VpcId`
@@ -2722,13 +2722,28 @@ public class LambdaService implements ResourceProvider {
400);
}
validateEnum(logging.get("LogFormat"), "loggingConfig.logFormat", List.of("JSON", "Text"));
// In the order Lambda lists them in the message (measured, eu-west-1, 2026-10-18).
validateEnum(logging.get("ApplicationLogLevel"), "loggingConfig.applicationLogLevel",
List.of("TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"));
List.of("FATAL", "TRACE", "WARN", "ERROR", "INFO", "DEBUG"));
validateEnum(logging.get("SystemLogLevel"), "loggingConfig.systemLogLevel",
List.of("DEBUG", "INFO", "WARN"));
List.of("WARN", "INFO", "DEBUG"));
// Measured on Lambda (eu-west-1, 2026-10-18): either level under Text, named or the default
// format, is refused on create and update alike, not stored and not ignored.
if ("Text".equals(logFormat(logging, durable)) && (nonBlank(logging.get("ApplicationLogLevel")) != null
|| nonBlank(logging.get("SystemLogLevel")) != null)) {
throw new AwsException("InvalidParameterValueException",
"LogLevel is not supported when LogFormat is set to \"Text\". Remove LogLevel from your "
+ "request or change the LogFormat to \"JSON\" and try again.", 400);
}
validateLogGroup(logging.get("LogGroup"));
}
/** The LogFormat a LoggingConfig names, else the function's default: JSON if durable, Text otherwise. */
private static String logFormat(Map<?, ?> logging, boolean durable) {
String named = nonBlank(logging.get("LogFormat"));
return named != null ? named : durable ? "JSON" : "Text";
}
static void validateEnum(Object value, String field, List<String> allowed) {
if (value == null || allowed.contains(value)) {
return;
@@ -2914,11 +2929,8 @@ public class LambdaService implements ResourceProvider {
* LoggingConfig is replaced wholesale, not merged: AWS resets any member the request omits
* back to its default, so an update that names only LogFormat drops a previously set LogGroup.
*
* <p>ApplicationLogLevel and SystemLogLevel are JSON-format-only: {@link #putLoggingConfig}
* never surfaces them for a Text-format function. Storing them anyway would leave state
* that is accepted, persisted and then never observable through any read path — the same
* accepted-then-forgotten shape this fix removes elsewhere — so they are only kept when the
* resolved format is JSON.
* <p>ApplicationLogLevel and SystemLogLevel are JSON-format-only: {@link #validateLoggingConfig}
* refuses either under Text, as Lambda does, so they are only ever stored for JSON.
*/
private static void applyLoggingConfig(LambdaFunction fn, Object value) {
if (!(value instanceof Map<?, ?> logging)) {
@@ -2938,26 +2950,21 @@ public class LambdaService implements ResourceProvider {
/**
* What Lambda stores for a LoggingConfig, once it is valid: an omitted LogFormat is the
* function's default, JSON for a durable function and Text otherwise, the two log levels count
* only in JSON, and a blank value is an omitted one, an omitted LogGroup meaning
* {@code /aws/lambda/<name>}. An invalid value is refused even where it would not be stored,
* a log level under Text included, so a comparison of these settings cannot pass it as
* unchanged.
* function's default, JSON for a durable function and Text otherwise, and a blank value is an
* omitted one, an omitted LogGroup meaning {@code /aws/lambda/<name>}. An invalid value is
* refused as Lambda refuses it, a log level under Text included, so a comparison of these
* settings cannot pass it as unchanged.
*/
public static LoggingSettings loggingSettings(Map<?, ?> logging, boolean durable) {
validateLoggingConfig(logging, durable);
String format = logging.get("LogFormat") instanceof String f && !f.isBlank() ? f : durable ? "JSON" : "Text";
boolean json = "JSON".equals(format);
return new LoggingSettings(format,
json ? nonBlank(logging.get("ApplicationLogLevel")) : null,
json ? nonBlank(logging.get("SystemLogLevel")) : null,
nonBlank(logging.get("LogGroup")));
return new LoggingSettings(logFormat(logging, durable), nonBlank(logging.get("ApplicationLogLevel")),
nonBlank(logging.get("SystemLogLevel")), nonBlank(logging.get("LogGroup")));
}
/** The function's stored logging settings, its default LogFormat when it has none stored. */
public static LoggingSettings loggingSettings(LambdaFunction fn) {
return new LoggingSettings(
fn.getLogFormat() != null ? fn.getLogFormat() : loggingSettings(Map.of(), fn.isDurable()).logFormat(),
fn.getLogFormat() != null ? fn.getLogFormat() : logFormat(Map.of(), fn.isDurable()),
fn.getApplicationLogLevel(), fn.getSystemLogLevel(), fn.getLogGroup());
}
@@ -98,6 +98,32 @@ class CloudFormationLambdaLoggingConfigIntegrationTest {
.body("LoggingConfig.ApplicationLogLevel", nullValue());
}
/**
* Measured on CloudFormation (eu-west-1, 2026-10-18): a valid log level under Text passes the
* template's validation but Lambda refuses it, so the update fails and the function keeps its
* configuration.
*/
@Test
void aLogLevelUnderTextFailsTheUpdate() {
String stackName = "cfn-lambda-logging-text-level-" + Long.toString(System.nanoTime(), 36);
registerDeletion(stackName);
deploy("CreateStack", stackName, template(""));
String created = functionName(stackName);
submit("UpdateStack", stackName, template("""
,"LoggingConfig": {"LogFormat": "Text", "ApplicationLogLevel": "WARN"}
"""));
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stackName);
assertNotEquals("UPDATE_COMPLETE", state.status(), state.reason());
given()
.when()
.get(LAMBDA + created + "/configuration")
.then()
.statusCode(200)
.body("LoggingConfig.LogFormat", equalTo("Text"))
.body("LoggingConfig.ApplicationLogLevel", nullValue());
}
private void registerDeletion(String stackName) {
cleanup.register(() -> {
submit("DeleteStack", stackName, null);
@@ -3014,7 +3014,9 @@ class LambdaServiceTest {
assertEquals(new LambdaService.LoggingSettings("JSON", null, null, null),
LambdaService.loggingSettings(Map.of(), true));
assertEquals(new LambdaService.LoggingSettings("Text", null, null, "/shared/app"),
LambdaService.loggingSettings(Map.of("ApplicationLogLevel", "WARN", "LogGroup", "/shared/app"), false));
LambdaService.loggingSettings(Map.of("LogGroup", "/shared/app"), false));
assertEquals(new LambdaService.LoggingSettings("JSON", "WARN", null, null),
LambdaService.loggingSettings(Map.of("ApplicationLogLevel", "WARN"), true));
assertEquals(new LambdaService.LoggingSettings("JSON", "WARN", null, null),
LambdaService.loggingSettings(Map.of("LogFormat", "JSON", "ApplicationLogLevel", "WARN",
"LogGroup", ""), false));
@@ -3028,6 +3030,21 @@ class LambdaServiceTest {
assertEquals("ValidationException", refused.getErrorCode());
}
@Test
void loggingSettingsRefuseALogLevelUnderText() {
for (Map<String, String> logging : List.of(
Map.of("LogFormat", "Text", "ApplicationLogLevel", "WARN"),
Map.of("LogFormat", "Text", "SystemLogLevel", "WARN"),
Map.of("ApplicationLogLevel", "WARN"))) {
AwsException refused = assertThrows(AwsException.class,
() -> LambdaService.loggingSettings(logging, false), logging.toString());
assertEquals("InvalidParameterValueException", refused.getErrorCode());
assertEquals("LogLevel is not supported when LogFormat is set to \"Text\". Remove LogLevel from your "
+ "request or change the LogFormat to \"JSON\" and try again.", refused.getMessage());
}
}
@Test
void aFunctionsLoggingSettingsFillInItsDefaultFormat() {
LambdaFunction fn = new LambdaFunction();
@@ -32,6 +32,8 @@ class LambdaVpcSnapStartLoggingIntegrationTest {
private static final String BASE_PATH = "/2015-03-31";
private static final String REGION = "us-east-1";
private static final String SECURITY_GROUP_ID = "sg-0123456789abcdef0";
private static final String LOG_LEVEL_UNDER_TEXT = "LogLevel is not supported when LogFormat is set to \"Text\". "
+ "Remove LogLevel from your request or change the LogFormat to \"JSON\" and try again.";
@Inject
Ec2Service ec2Service;
@@ -389,7 +391,7 @@ class LambdaVpcSnapStartLoggingIntegrationTest {
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("1 validation error detected: Value 'VERBOSE' at "
+ "'loggingConfig.applicationLogLevel' failed to satisfy constraint: Member must satisfy "
+ "enum value set: [TRACE, DEBUG, INFO, WARN, ERROR, FATAL]"));
+ "enum value set: [FATAL, TRACE, WARN, ERROR, INFO, DEBUG]"));
}
@Test
@@ -412,7 +414,60 @@ class LambdaVpcSnapStartLoggingIntegrationTest {
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("1 validation error detected: Value 'TRACE' at "
+ "'loggingConfig.systemLogLevel' failed to satisfy constraint: Member must satisfy "
+ "enum value set: [DEBUG, INFO, WARN]"));
+ "enum value set: [WARN, INFO, DEBUG]"));
}
/**
* Measured on Lambda (eu-west-1, 2026-10-18): a log level under Text, the format named or left
* to its default, is refused, whichever of the two levels it is.
*/
@Test
void aLogLevelUnderTextIsRefusedOnCreate() {
for (String loggingConfig : List.of(
"{\"LogFormat\": \"Text\", \"ApplicationLogLevel\": \"WARN\"}",
"{\"LogFormat\": \"Text\", \"SystemLogLevel\": \"WARN\"}",
"{\"ApplicationLogLevel\": \"WARN\"}")) {
given()
.contentType("application/json")
.body("""
{
"FunctionName": "logging-text-level-fn",
"Runtime": "nodejs20.x",
"Role": "arn:aws:iam::000000000000:role/lambda-role",
"Handler": "index.handler",
"LoggingConfig": %s
}
""".formatted(loggingConfig))
.when()
.post(BASE_PATH + "/functions")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"))
.body("message", equalTo(LOG_LEVEL_UNDER_TEXT));
}
}
@Test
void aLogLevelUnderTextIsRefusedOnUpdateAndTheFunctionKeepsItsLogging() {
createFunction("logging-text-level-update-fn", "");
given()
.contentType("application/json")
.body("{\"LoggingConfig\": {\"ApplicationLogLevel\": \"WARN\"}}")
.when()
.put(BASE_PATH + "/functions/logging-text-level-update-fn/configuration")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"))
.body("message", equalTo(LOG_LEVEL_UNDER_TEXT));
given()
.when()
.get(BASE_PATH + "/functions/logging-text-level-update-fn/configuration")
.then()
.statusCode(200)
.body("LoggingConfig.LogFormat", equalTo("Text"))
.body("LoggingConfig.ApplicationLogLevel", nullValue());
}
@Test
@@ -496,26 +551,6 @@ class LambdaVpcSnapStartLoggingIntegrationTest {
.body("__type", equalTo("ValidationException"));
}
@Test
void textFormatLogLevelsAreAcceptedButNeverStoredOrReturned() {
createFunction("logging-text-levels-fn", """
,
"LoggingConfig": {
"LogFormat": "Text",
"ApplicationLogLevel": "DEBUG",
"SystemLogLevel": "WARN"
}""");
given()
.when()
.get(BASE_PATH + "/functions/logging-text-levels-fn/configuration")
.then()
.statusCode(200)
.body("LoggingConfig.LogFormat", equalTo("Text"))
.body("LoggingConfig.ApplicationLogLevel", nullValue())
.body("LoggingConfig.SystemLogLevel", nullValue());
}
@Test
void updateFunctionConfigurationDetachesVpcConfigAndClearsVpcId() {
createFunction("vpc-detach-fn", vpcConfigJson());