diff --git a/docs/services/step-functions.md b/docs/services/step-functions.md index 83daa91e33..fbc0ed2e2d 100644 --- a/docs/services/step-functions.md +++ b/docs/services/step-functions.md @@ -765,8 +765,10 @@ timestamps. Opaque dictionary keys, including secret version IDs and ECS log options, retain their original spelling. `describeSecret` returns metadata without the secret value. Disabled services fail with a catchable service exception. -The Lambda `updateEventSourceMapping` SDK task takes `Uuid` in JSONPath -`Parameters` or JSONata `Arguments`. The direct Lambda REST API still uses `UUID`. +Lambda `updateEventSourceMapping` tasks identify the mapping with `Uuid` in +JSONPath `Parameters` or JSONata `Arguments`, following the Step Functions SDK +parameter spelling. The direct Lambda API and existing task-result fields retain +their `UUID` spelling. ECS `listServices` supports the same `MaxResults` and opaque `NextToken` as the direct ECS API. Lambda mapping tasks currently return an unpaginated list; diff --git a/src/test/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvokerTest.java b/src/test/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvokerTest.java index 9cce8a80c0..47f471a3c4 100644 --- a/src/test/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvokerTest.java +++ b/src/test/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvokerTest.java @@ -9,6 +9,8 @@ import io.floci.aws.services.lambda.LambdaController; import io.floci.aws.services.secretsmanager.SecretsManagerJsonHandler; import jakarta.ws.rs.core.Response; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import static org.junit.jupiter.api.Assertions.*; @@ -25,20 +27,35 @@ class SdkManagementTaskInvokerTest { lambda, mock(SecretsManagerJsonHandler.class), registry, mapper); @Test - void usesSdkUuidWithoutChangingTheLambdaRequestBodyOrInput() throws Exception { + void lambdaMappingUpdateUsesSdkUuidWithoutMutatingTheTaskInput() throws Exception { when(registry.isServiceEnabled("lambda")).thenReturn(true); when(lambda.updateEventSourceMapping(eq("mapping-id"), anyString())) .thenReturn(Response.ok(mapper.readTree("{\"UUID\":\"mapping-id\",\"State\":\"Disabled\"}")).build()); - JsonNode input = mapper.readTree("{\"Uuid\":\"mapping-id\",\"Enabled\":false,\"BatchSize\":3}"); + JsonNode request = mapper.readTree("{\"Uuid\":\"mapping-id\",\"Enabled\":false,\"BatchSize\":3}"); - JsonNode result = invoker.invoke(StatesIntegration.parse( - "arn:aws:states:::aws-sdk:lambda:updateEventSourceMapping").orElseThrow(), input, "eu-west-2"); + JsonNode result = invoker.invoke(lambdaMappingIntegration(), request, "eu-west-2"); ArgumentCaptor body = ArgumentCaptor.forClass(String.class); verify(lambda).updateEventSourceMapping(eq("mapping-id"), body.capture()); assertEquals(mapper.readTree("{\"Enabled\":false,\"BatchSize\":3}"), mapper.readTree(body.getValue())); - assertEquals("mapping-id", input.path("Uuid").asText()); + assertEquals("mapping-id", request.path("Uuid").asText()); assertEquals("mapping-id", result.path("UUID").asText()); + assertEquals("Disabled", result.path("State").asText()); + } + + @ParameterizedTest + @ValueSource(strings = {"{}", "{\"Uuid\":null}", "{\"Uuid\":\"\"}", "{\"Uuid\":\" \"}", + "{\"UUID\":\"mapping-id\"}"}) + void lambdaMappingUpdateRejectsInvalidSdkUuidRequests(String requestJson) throws Exception { + when(registry.isServiceEnabled("lambda")).thenReturn(true); + JsonNode request = mapper.readTree(requestJson); + + AslExecutor.FailStateException error = assertThrows(AslExecutor.FailStateException.class, + () -> invoker.invoke(lambdaMappingIntegration(), request, "eu-west-2")); + + assertEquals("Lambda.InvalidParameterValueException", error.error); + assertEquals("Uuid is required.", error.cause); + verifyNoInteractions(lambda); } @Test @@ -106,4 +123,8 @@ class SdkManagementTaskInvokerTest { private static StatesIntegration integration() { return StatesIntegration.parse("arn:aws:states:::aws-sdk:ecs:updateService").orElseThrow(); } + + private static StatesIntegration lambdaMappingIntegration() { + return StatesIntegration.parse("arn:aws:states:::aws-sdk:lambda:updateEventSourceMapping").orElseThrow(); + } } diff --git a/src/test/java/io/floci/aws/services/stepfunctions/StepFunctionsSdkManagementIntegrationTest.java b/src/test/java/io/floci/aws/services/stepfunctions/StepFunctionsSdkManagementIntegrationTest.java index 977174658e..f5b3d2fb23 100644 --- a/src/test/java/io/floci/aws/services/stepfunctions/StepFunctionsSdkManagementIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/stepfunctions/StepFunctionsSdkManagementIntegrationTest.java @@ -126,14 +126,22 @@ class StepFunctionsSdkManagementIntegrationTest { try { JsonNode listed = task("lambda", "listEventSourceMappings", Map.of("FunctionName", function), region, "aws"); assertEquals(uuid, listed.path("EventSourceMappings").get(0).path("UUID").asText()); - JsonNode updated = runTask("lambda", "updateEventSourceMapping", Map.of("Uuid", uuid, - "Enabled", false, "BatchSize", 3), region, "aws", ACCOUNT, false, queryLanguage); - assertEquals(uuid, updated.path("UUID").asText()); - assertEquals(3, updated.path("BatchSize").asInt()); - assertEquals("Disabled", updated.path("State").asText()); - assertTrue(updated.path("LastModified").isTextual()); - assertEquals(3, lambda("get", "/2015-03-31/event-source-mappings/" + uuid, Map.of(), region) - .path("BatchSize")); + boolean jsonata = "JSONata".equals(queryLanguage); + for (boolean enabled : List.of(true, false)) { + JsonNode updated = runTask("lambda", "updateEventSourceMapping", Map.of( + jsonata ? "Uuid" : "Uuid.$", jsonata ? "{% $states.input.mappingId %}" : "$.mappingId", + "Enabled", enabled, "BatchSize", 3), region, "aws", ACCOUNT, false, + queryLanguage, Map.of("mappingId", uuid)); + assertEquals(uuid, updated.path("UUID").asText()); + assertEquals(3, updated.path("BatchSize").asInt()); + String state = enabled ? "Enabled" : "Disabled"; + assertEquals(state, updated.path("State").asText()); + assertTrue(updated.path("LastModified").isTextual()); + Response mapping = lambda("get", "/2015-03-31/event-source-mappings/" + uuid, Map.of(), region); + assertEquals(uuid, mapping.path("UUID")); + assertEquals(3, mapping.path("BatchSize")); + assertEquals(state, mapping.path("State")); + } JsonNode pagination = runTask("lambda", "listEventSourceMappings", Map.of("FunctionName", function, "MaxItems", 1), region, "aws", ACCOUNT, true); assertEquals("Lambda.InvalidParameterValueException", pagination.path("Error").asText()); @@ -153,12 +161,12 @@ class StepFunctionsSdkManagementIntegrationTest { private static JsonNode runTask(String service, String action, Map parameters, String region, String partition, String account, boolean catchError) throws Exception { - return runTask(service, action, parameters, region, partition, account, catchError, "JSONPath"); + return runTask(service, action, parameters, region, partition, account, catchError, "JSONPath", Map.of()); } private static JsonNode runTask(String service, String action, Map parameters, String region, String partition, String account, boolean catchError, - String queryLanguage) throws Exception { + String queryLanguage, Map input) throws Exception { ObjectNode task = MAPPER.createObjectNode().put("Type", "Task").put("End", true) .put("Resource", "arn:" + partition + ":states:::aws-sdk:" + service + ":" + action); task.set("JSONata".equals(queryLanguage) ? "Arguments" : "Parameters", MAPPER.valueToTree(parameters)); @@ -181,7 +189,8 @@ class StepFunctionsSdkManagementIntegrationTest { .roleArn("arn:" + partition + ":iam::" + account + ":role/test-role") .definition(definition.toString())).stateMachineArn(); try { - String execution = client.startExecution(request -> request.stateMachineArn(arn).input("{}")) + String execution = client.startExecution(request -> request.stateMachineArn(arn) + .input(MAPPER.valueToTree(input).toString())) .executionArn(); await().atMost(Duration.ofSeconds(10)).until(() -> !"RUNNING".equals(client.describeExecution( request -> request.executionArn(execution)).statusAsString()));