fix(stepfunctions): preserve Scheduler task timestamps (#4056)

Co-authored-by: Vamsi Akavarapu <16164447+vamsiak@users.noreply.github.com>
This commit is contained in:
vamsiakandVamsi Akavarapu authored and GitHub committed 2026-09-21 08:30:44 -04:00
1 parent e4c75e4f17
commit 25a74be198
3 files changed
+137 -1

No files matched your search

+3
View File
@@ -429,6 +429,9 @@ the wire and the task fails with `Sfn.StateMachineDoesNotExistException`.
| `arn:aws:states:::aws-sdk:scheduler:deleteSchedule` | `{}` | `Scheduler.ResourceNotFoundException` |
| `arn:aws:states:::aws-sdk:sns:publish` | `{MessageId}` | `Sns.NotFoundException` when the topic does not exist |
Scheduler create and update tasks accept `StartDate` and `EndDate` as RFC 3339 strings, including
offsets and fractional seconds. The direct Scheduler API continues to use numeric epoch seconds.
`sendTaskSuccess` and `sendTaskFailure` resolve a token a `.waitForTaskToken` task is parked on. A
token nobody is waiting for fails the calling task rather than reporting a delivery that never
happened.
@@ -84,6 +84,7 @@ import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
@@ -1392,7 +1393,8 @@ public class AslExecutor {
input.path("GroupName").asText(null), region);
return objectMapper.createObjectNode();
}
ScheduleRequest request = schedulerController.parseScheduleRequest(input);
ScheduleRequest request = schedulerController.parseScheduleRequest(
normalizeAwsSdkSchedulerInput(input));
request.setName(input.path("Name").asText(null));
Schedule schedule = creating
? schedulerService.createSchedule(request, region)
@@ -1405,6 +1407,37 @@ public class AslExecutor {
}
}
/** Converts the SDK's RFC 3339 timestamps to the epoch-second values used by the wire parser. */
private JsonNode normalizeAwsSdkSchedulerInput(JsonNode input) {
JsonNode normalized = input.deepCopy();
if (normalized instanceof ObjectNode object) {
normalizeAwsSdkSchedulerTimestamp(object, "StartDate");
normalizeAwsSdkSchedulerTimestamp(object, "EndDate");
}
return normalized;
}
private void normalizeAwsSdkSchedulerTimestamp(ObjectNode input, String field) {
JsonNode value = input.get(field);
if (value == null || value.isNull() || value.isNumber()) {
return;
}
if (!value.isTextual()) {
throw malformedAwsSdkSchedulerTimestamp(field);
}
try {
Instant instant = Instant.parse(value.textValue());
input.put(field, instant.getEpochSecond() + instant.getNano() / 1_000_000_000d);
} catch (DateTimeParseException ignored) {
// AWS exposes SDK timestamp deserialization failures as SerializationException.
throw malformedAwsSdkSchedulerTimestamp(field);
}
}
private static AwsException malformedAwsSdkSchedulerTimestamp(String field) {
return new AwsException("SerializationException", field + " must be an RFC 3339 timestamp.", 400);
}
/**
* Optimized EventBridge integration for {@code events:putEvents}. The task result is the
* PutEvents response itself, and one failed entry fails the whole task with
@@ -545,6 +545,106 @@ class StepFunctionsAwsSdkTaskIntegrationTest {
assertEquals("Scheduler.ValidationException", result.path("caughtError").asText());
}
@Test
@Order(20)
void createScheduleAcceptsRfc3339DatesFromJsonata() throws Exception {
String stateMachineArn = createStateMachine("aws-sdk-create-schedule-dates", """
{
"QueryLanguage": "JSONata",
"StartAt": "Schedule",
"States": {
"Schedule": {
"Type": "Task",
"Resource": "arn:aws:states:::aws-sdk:scheduler:createSchedule",
"Arguments": {
"Name": "payout-dated",
"ScheduleExpression": "rate(1 day)",
"StartDate": "2099-01-01T05:30:00.500+05:30",
"EndDate": "2099-01-02T00:00:00Z",
"FlexibleTimeWindow": {"Mode": "OFF"},
"Target": {"Arn": "TARGET_ARN", "RoleArn": "ROLE"}
},
"End": true
}
}
}
""".replace("TARGET_ARN", quickChildArn).replace("ROLE", ROLE_ARN));
succeedingOutputOf(stateMachineArn, "{}");
JsonNode schedule = mapper.readTree(given().when().get("/schedules/payout-dated")
.then().statusCode(200).extract().body().asString());
assertEquals(4070908800.5d, schedule.path("StartDate").asDouble(), 0.001d);
assertEquals(4070995200L, Math.round(schedule.path("EndDate").asDouble()));
}
@Test
@Order(21)
void updateScheduleAcceptsRfc3339DatesFromJsonPath() throws Exception {
String stateMachineArn = createStateMachine("aws-sdk-update-schedule-dates", """
{
"StartAt": "Schedule",
"States": {
"Schedule": {
"Type": "Task",
"Resource": "arn:aws:states:::aws-sdk:scheduler:updateSchedule",
"Parameters": {
"Name": "payout-dated",
"ScheduleExpression": "rate(2 days)",
"StartDate": "2099-02-01T00:00:00Z",
"EndDate": "2099-02-02T00:00:00Z",
"FlexibleTimeWindow": {"Mode": "OFF"},
"Target": {"Arn": "TARGET_ARN", "RoleArn": "ROLE"}
},
"End": true
}
}
}
""".replace("TARGET_ARN", quickChildArn).replace("ROLE", ROLE_ARN));
succeedingOutputOf(stateMachineArn, "{}");
JsonNode schedule = mapper.readTree(given().when().get("/schedules/payout-dated")
.then().statusCode(200).extract().body().asString());
assertEquals(4073587200L, Math.round(schedule.path("StartDate").asDouble()));
assertEquals(4073673600L, Math.round(schedule.path("EndDate").asDouble()));
given().when().delete("/schedules/payout-dated").then().statusCode(200);
}
@Test
@Order(22)
void malformedScheduleDateIsCatchableAsSerializationException() throws Exception {
String stateMachineArn = createStateMachine("aws-sdk-create-schedule-bad-date", """
{
"QueryLanguage": "JSONata",
"StartAt": "Schedule",
"States": {
"Schedule": {
"Type": "Task",
"Resource": "arn:aws:states:::aws-sdk:scheduler:createSchedule",
"Arguments": {
"Name": "payout-bad-date",
"ScheduleExpression": "rate(1 day)",
"StartDate": "tomorrow",
"FlexibleTimeWindow": {"Mode": "OFF"},
"Target": {"Arn": "TARGET_ARN", "RoleArn": "ROLE"}
},
"Catch": [{
"ErrorEquals": ["Scheduler.SerializationException"],
"Next": "Recovered",
"Output": {"caughtError": "{% $states.errorOutput.Error %}"}
}],
"End": true
},
"Recovered": {"Type": "Pass", "End": true}
}
}
""".replace("TARGET_ARN", quickChildArn).replace("ROLE", ROLE_ARN));
JsonNode result = mapper.readTree(succeedingOutputOf(stateMachineArn, "{}"));
assertEquals("Scheduler.SerializationException", result.path("caughtError").asText());
}
private static String deleteScheduleTask(String scheduleName, String groupName) {
String groupArgument = groupName == null ? "" : ", \"GroupName\": \"" + groupName + "\"";
return """