diff --git a/src/main/java/io/floci/aws/services/stepfunctions/AslExecutor.java b/src/main/java/io/floci/aws/services/stepfunctions/AslExecutor.java index 104a212422..518d6d07c3 100644 --- a/src/main/java/io/floci/aws/services/stepfunctions/AslExecutor.java +++ b/src/main/java/io/floci/aws/services/stepfunctions/AslExecutor.java @@ -1573,6 +1573,12 @@ public class AslExecutor { // variant arrives here as the bare runTask resource and simply launches the task while the token // future blocks for SendTaskSuccess. if (integration.isAnySuffix("ecs", "runTask")) { + // AWS defines request-response, .sync and .waitForTaskToken for ecs:runTask, so any other + // pattern (.sync:2) is refused before a task is launched rather than after. + String suffix = integration.suffix(); + if (!suffix.isEmpty() && !".sync".equals(suffix) && !".waitForTaskToken".equals(suffix)) { + throw OptimizedIntegrations.unsupported(integration); + } // A non-null taskToken means the original resource ended with .waitForTaskToken (stripped // upstream). Its failure semantics match .sync — a task placement failure fails the state — // whereas request-response returns the {Tasks,Failures} envelope without failing the state. @@ -2339,12 +2345,6 @@ public class AslExecutor { return resp; } - if (!".sync".equals(mode)) { - // Only request-response (""), .sync and .waitForTaskToken are valid; reject typos rather - // than silently treating an unknown suffix as .sync. - throw new FailStateException("States.TaskFailed", "Unsupported ecs:runTask mode: " + mode); - } - // .sync — wait until every launched task reaches STOPPED, then surface success or failure. // All tasks must be polled (not just the first): with Count > 1, a failure in any task must // fail the state, otherwise tasks beyond the first would run unmonitored. The wait is bounded diff --git a/src/test/java/io/floci/aws/services/stepfunctions/AslExecutorEcsRunTaskModeTest.java b/src/test/java/io/floci/aws/services/stepfunctions/AslExecutorEcsRunTaskModeTest.java index bf5e756394..84edcda9d4 100644 --- a/src/test/java/io/floci/aws/services/stepfunctions/AslExecutorEcsRunTaskModeTest.java +++ b/src/test/java/io/floci/aws/services/stepfunctions/AslExecutorEcsRunTaskModeTest.java @@ -34,6 +34,7 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -120,6 +121,19 @@ class AslExecutorEcsRunTaskModeTest { assertEquals("AmazonECS.Unknown", execution.getError()); } + @Test + void syncTwoIsRefusedBeforeAnyTaskIsLaunched() { + launchOneTask(); + + Execution execution = run("arn:aws:states:::ecs:runTask.sync:2", + "{\"TaskDefinition\":\"my-task-def\"}"); + + assertEquals("FAILED", execution.getStatus()); + assertEquals("States.TaskFailed", execution.getError()); + assertEquals("Unsupported resource: arn:aws:states:::ecs:runTask.sync:2", execution.getCause()); + verify(ecsService, never()).runTask(any(), any(), anyInt(), any(), any(), any(), any(), any(), any()); + } + @Test void networkConfigurationIsThreadedThroughToRunTask() throws Exception { when(ecsService.runTask(any(), any(), anyInt(), any(), any(), any(), any(), any(), any()))