Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

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

Sam Fakhreddine29319fbfb5f8
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
index c289d749b5..9b426f7849 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
@@ -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"));
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/EsmIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/EsmIntegrationTest.java
index 2cbe43472d..0f0d17c910 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/EsmIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/EsmIntegrationTest.java
@@ -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);
+ }
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java
index 25a9ab5646..0e68570888 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java
@@ -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());
+ }
}