fix(lambda): default event source mapping BatchSize by source type (#5362)

CreateEventSourceMapping stored BatchSize 10 for every event source when
the request omitted it. The Lambda model documents a per-source default:
10 for SQS and 100 for Kinesis, DynamoDB Streams, Amazon MSK, self-managed
Apache Kafka, Amazon MQ and DocumentDB. SQS mappings keep 10; every other
source now defaults to 100.

updateEventSourceMapping_invalidLaterField_leavesBatchSizeAndEnabledUnchanged
asserted the untouched Kafka mapping kept the old default of 10; it now
expects 100.

Fixes #4740
This commit is contained in:
Sam Fakhreddine authored and GitHub committed 2026-10-10 14:02:20 -04:00
1 parent 1082941bc2
commit 29319fbfb5
3 files changed
+42 -2

No files matched your search

@@ -97,6 +97,8 @@ public class LambdaService implements ResourceProvider {
private static final Pattern S3_BUCKET_PATTERN = Pattern.compile("[0-9A-Za-z\\.\\-_]*(?<!\\.)");
// Create/UpdateAlias FunctionVersion (VersionWithLatestPublished: 1-1024, pattern below) and Description (max 256).
private static final Pattern ALIAS_FUNCTION_VERSION_PATTERN = Pattern.compile("(\\$LATEST(\\.PUBLISHED)?|[0-9]+)");
private static final int DEFAULT_SQS_BATCH_SIZE = 10;
private static final int DEFAULT_STREAM_BATCH_SIZE = 100;
// The model's own Role pattern, which AWS quotes verbatim in its validation message; it
// already accepts every partition.
private static final Pattern ROLE_ARN_PATTERN = Pattern.compile(
@@ -1506,7 +1508,10 @@ public class LambdaService implements ResourceProvider {
ResolvedFunctionTarget target = resolveFunctionTarget(resolvedRegion, fnRef);
int batchSize = toInt(request.get("BatchSize"), 10);
// The model documents a per-source default: 10 for SQS, 100 for every other source type.
int defaultBatchSize = eventSourceArn != null && eventSourceArn.contains(":sqs:")
? DEFAULT_SQS_BATCH_SIZE : DEFAULT_STREAM_BATCH_SIZE;
int batchSize = toInt(request.get("BatchSize"), defaultBatchSize);
Integer maximumBatchingWindowInSeconds = parseMaximumBatchingWindow(request);
boolean enabled = !Boolean.FALSE.equals(request.get("Enabled"));
@@ -1844,4 +1844,26 @@ class EsmIntegrationTest {
given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuid);
}
}
@Test
@Order(94)
void sqsEventSourceMappingWithoutBatchSizeDefaultsTo10() {
// Catches: the per-source BatchSize default also raising SQS mappings from 10 to 100
String uuid = given()
.contentType("application/json")
.body("""
{
"FunctionName": "%s",
"EventSourceArn": "%s"
}
""".formatted(FUNCTION_NAME, QUEUE_ARN))
.when()
.post(LAMBDA_BASE + "/event-source-mappings")
.then()
.statusCode(202)
.body("BatchSize", equalTo(10))
.extract()
.path("UUID");
given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuid).then().statusCode(202);
}
}
@@ -1971,7 +1971,7 @@ class LambdaServiceTest {
"FunctionResponseTypes", List.of("Bogus"))));
EventSourceMapping stored = service.getEventSourceMapping(esm.getUuid());
assertEquals(10, stored.getBatchSize());
assertEquals(100, stored.getBatchSize());
assertTrue(stored.isEnabled());
}
@@ -2536,4 +2536,17 @@ class LambdaServiceTest {
assertEquals("ValidationException", error.getErrorCode());
assertEquals("original", service.getAlias(REGION, "alias-description-fn", "live").getDescription());
}
@Test
void createEventSourceMapping_selfManagedKafkaWithoutBatchSize_defaultsTo100() {
// Catches: every event source defaulting to BatchSize 10, where AWS uses 10 only for SQS
service.createFunction(REGION, baseRequest("kafka-default-batch-fn"));
EventSourceMapping esm = service.createEventSourceMapping(REGION, Map.of(
"FunctionName", "kafka-default-batch-fn",
"Topics", List.of("my-topic"),
"SelfManagedEventSource", Map.of("Endpoints", Map.of("KAFKA_BOOTSTRAP_SERVERS", List.of("localhost:9092")))));
assertEquals(100, esm.getBatchSize());
}
}