Light, fluffy, and always free - The AWS Local Emulator alternative
fix(lambda): return event source mapping failure config (#1629)
Vinod Kumar Bengaluruaf0ec51f98b1
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.javaindex 3fbe1cdaf3..846b31143c 100644--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java@@ -330,6 +330,17 @@ public class LambdaController {node.put("State", esm.getState());node.put("LastModified", (double) esm.getLastModified() / 1000.0);ArrayNode responseTypes = node.putArray("FunctionResponseTypes");++ if (esm.getBisectBatchOnFunctionError() != null) {+ node.put("BisectBatchOnFunctionError", esm.getBisectBatchOnFunctionError());+ }++ if (esm.getDestinationConfig() != null && esm.getDestinationConfig().getOnFailure() != null) {+ ObjectNode destinationConfig = node.putObject("DestinationConfig");+ ObjectNode onFailure = destinationConfig.putObject("OnFailure");+ onFailure.put("Destination", esm.getDestinationConfig().getOnFailure().getDestination());+ }+if (esm.getFunctionResponseTypes() != null) {esm.getFunctionResponseTypes().forEach(responseTypes::add);}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.javaindex d0a96d700f..c1dea94957 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@@ -709,6 +709,12 @@ public class LambdaService {ScalingConfig scalingConfig = parseScalingConfig(request, eventSourceArn);+ Boolean bisectBatchOnFunctionError = request.get("BisectBatchOnFunctionError") instanceof Boolean b+ ? b+ : null;++ EventSourceMapping.DestinationConfig destinationConfig = parseDestinationConfig(request);+String queueUrl = eventSourceArn.contains(":sqs:") ? AwsArnUtils.arnToQueueUrl(eventSourceArn, config.effectiveBaseUrl()) : null;EventSourceMapping esm = new EventSourceMapping();@@ -724,6 +730,8 @@ public class LambdaService {esm.setState(enabled ? "Enabled" : "Disabled");esm.setScalingConfig(scalingConfig);esm.setFunctionResponseTypes(functionResponseTypes);+ esm.setBisectBatchOnFunctionError(bisectBatchOnFunctionError);+ esm.setDestinationConfig(destinationConfig);esm.setLastModified(System.currentTimeMillis());esmStore.save(esm);@@ -734,6 +742,38 @@ public class LambdaService {return esm;}+ private EventSourceMapping.DestinationConfig parseDestinationConfig(Map<String, Object> request) {+ Object raw = request.get("DestinationConfig");+ if (raw == null) {+ return null;+ }+ if (!(raw instanceof Map<?, ?> destMap)) {+ throw new AwsException("InvalidParameterValueException",+ "DestinationConfig must be a JSON object", 400);+ }++ Object rawOnFailure = destMap.get("OnFailure");+ if (rawOnFailure == null) {+ return null;+ }+ if (!(rawOnFailure instanceof Map<?, ?> onFailureMap)) {+ throw new AwsException("InvalidParameterValueException",+ "DestinationConfig.OnFailure must be a JSON object", 400);+ }++ Object destination = onFailureMap.get("Destination");+ if (destination == null) {+ return null;+ }++ EventSourceMapping.OnFailure onFailure = new EventSourceMapping.OnFailure();+ onFailure.setDestination(String.valueOf(destination));++ EventSourceMapping.DestinationConfig destinationConfig = new EventSourceMapping.DestinationConfig();+ destinationConfig.setOnFailure(onFailure);+ return destinationConfig;+ }+/*** Parses {@code ScalingConfig} out of a create/update request and applies* AWS-level validation: {@code MaximumConcurrency} must be in [2, 1000]@@ -836,6 +876,15 @@ public class LambdaService {esm.setScalingConfig(parseScalingConfig(request, esm.getEventSourceArn()));}+ if (request.containsKey("BisectBatchOnFunctionError")) {+ Object raw = request.get("BisectBatchOnFunctionError");+ esm.setBisectBatchOnFunctionError(raw instanceof Boolean b ? b : null);+ }++ if (request.containsKey("DestinationConfig")) {+ esm.setDestinationConfig(parseDestinationConfig(request));+ }+esm.setLastModified(System.currentTimeMillis());esmStore.save(esm);diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/model/EventSourceMapping.java b/src/main/java/io/github/hectorvent/floci/services/lambda/model/EventSourceMapping.javaindex 548aa40eee..ac44e15e2e 100644--- a/src/main/java/io/github/hectorvent/floci/services/lambda/model/EventSourceMapping.java+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/model/EventSourceMapping.java@@ -1,6 +1,7 @@package io.github.hectorvent.floci.services.lambda.model;import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import io.quarkus.runtime.annotations.RegisterForReflection;import java.util.ArrayList;@@ -26,6 +27,8 @@ public class EventSourceMapping {private List<String> functionResponseTypes = new ArrayList<>();private Map<String, String> shardSequenceNumbers = new HashMap<>();private ScalingConfig scalingConfig;+ private Boolean bisectBatchOnFunctionError;+ private DestinationConfig destinationConfig;public EventSourceMapping() {}@@ -84,4 +87,50 @@ public class EventSourceMapping {public Integer getMaximumConcurrency() {return scalingConfig != null ? scalingConfig.getMaximumConcurrency() : null;}++ public Boolean getBisectBatchOnFunctionError() {+ return bisectBatchOnFunctionError;+ }++ public void setBisectBatchOnFunctionError(Boolean bisectBatchOnFunctionError) {+ this.bisectBatchOnFunctionError = bisectBatchOnFunctionError;+ }++ public DestinationConfig getDestinationConfig() {+ return destinationConfig;+ }++ public void setDestinationConfig(DestinationConfig destinationConfig) {+ this.destinationConfig = destinationConfig;+ }++ public static class DestinationConfig {+ private OnFailure onFailure;++ public DestinationConfig() {+ }++ public OnFailure getOnFailure() {+ return onFailure;+ }++ public void setOnFailure(OnFailure onFailure) {+ this.onFailure = onFailure;+ }+ }++ public static class OnFailure {+ private String destination;++ public OnFailure() {+ }++ public String getDestination() {+ return destination;+ }++ public void setDestination(String destination) {+ this.destination = destination;+ }+ }}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.javaindex 4b5c019a5d..23246f8309 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@@ -134,6 +134,86 @@ class EsmIntegrationTest {given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuid).then().statusCode(202);}+ @Test+ void updateEventSourceMappingReturnsFailureConfig() {+ String streamArn = "arn:aws:dynamodb:us-east-1:000000000000:table/esm-table/stream/2026-01-01T00:00:00.000";+ String destinationArn = "arn:aws:sqs:us-east-1:000000000000:esm-updated-failure-config-dlq";++ String uuid = given()+ .contentType("application/json")+ .body("""+ {+ "FunctionName": "%s",+ "EventSourceArn": "%s"+ }+ """.formatted(FUNCTION_NAME, streamArn))+ .when()+ .post(LAMBDA_BASE + "/event-source-mappings/")+ .then()+ .statusCode(202)+ .body("$", not(hasKey("BisectBatchOnFunctionError")))+ .body("$", not(hasKey("DestinationConfig")))+ .extract()+ .path("UUID");++ given()+ .contentType("application/json")+ .body("""+ {+ "BisectBatchOnFunctionError": true,+ "DestinationConfig": {+ "OnFailure": {+ "Destination": "%s"+ }+ }+ }+ """.formatted(destinationArn))+ .when()+ .put(LAMBDA_BASE + "/event-source-mappings/" + uuid)+ .then()+ .statusCode(202)+ .body("BisectBatchOnFunctionError", equalTo(true))+ .body("DestinationConfig.OnFailure.Destination", equalTo(destinationArn));++ given()+ .when()+ .get(LAMBDA_BASE + "/event-source-mappings/" + uuid)+ .then()+ .statusCode(200)+ .body("BisectBatchOnFunctionError", equalTo(true))+ .body("DestinationConfig.OnFailure.Destination", equalTo(destinationArn));++ given()+ .delete(LAMBDA_BASE + "/event-source-mappings/" + uuid)+ .then()+ .statusCode(202);+ }++ @Test+ void responseOmitsFailureConfigWhenUnset() {+ 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("$", not(hasKey("BisectBatchOnFunctionError")))+ .body("$", not(hasKey("DestinationConfig")))+ .extract()+ .path("UUID");++ given()+ .delete(LAMBDA_BASE + "/event-source-mappings/" + uuid)+ .then()+ .statusCode(202);+ }+@Test@Order(5)void createEventSourceMappingForNonExistentFunction() {