fix(scheduler): 🐛 support aws-sdk universal targets and FIFO MessageGroupId (#1344)

ScheduleInvoker routed solely by substring-matching the target ARN, so a
universal target (arn:aws:scheduler:::aws-sdk:sns:publish) matched the
":sns:" branch and passed the universal-target ARN itself to SnsService as
the topic, failing at fire time with "Topic does not exist". The real
TopicArn carried in the target Input was never read.

Detect the aws-sdk:<service>:<action> form before the ARN routing and
dispatch sns:publish / sqs:sendMessage using the parameters parsed from
Input. Also add Target.SqsParameters so templated FIFO SQS targets honor
MessageGroupId instead of failing with "The request must contain the
parameter MessageGroupId".

Closes #1265
This commit is contained in:
Lorenzo Galassi authored and GitHub committed 2026-06-15 23:29:03 -05:00
1 parent eb730a455e
commit ed102b0ed2
6 files changed
+250 -5

No files matched your search

@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.scheduler;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
@@ -19,9 +20,11 @@ import java.util.Map;
/**
* Delivers an EventBridge Scheduler target invocation to the underlying service.
* Supports SQS, Lambda, SNS, and EventBridge PutEvents targets — mirrors the
* subset handled by {@code EventBridgeInvoker} but using Scheduler's
* {@link Target} model (raw {@code input} string, no JSONPath/template).
* Supports templated SQS, Lambda, SNS, and EventBridge PutEvents targets, plus
* universal targets ({@code arn:aws:scheduler:::aws-sdk:<service>:<action>}) for
* {@code sns:publish} and {@code sqs:sendMessage}. Mirrors the subset handled by
* {@code EventBridgeInvoker} but using Scheduler's {@link Target} model (raw
* {@code input} string, no JSONPath/template).
*/
@ApplicationScoped
public class ScheduleInvoker {
@@ -56,11 +59,23 @@ public class ScheduleInvoker {
}
String arn = target.getArn();
String payload = target.getInput() != null ? target.getInput() : "{}";
String targetRegion = extractRegion(arn, region);
// Universal targets (arn:aws:scheduler:::aws-sdk:<service>:<action>) carry the
// real resource identifiers inside Input, not in the target ARN. Detect and
// dispatch them before the ARN-substring routing below, which would otherwise
// mis-match (e.g. "aws-sdk:sns:publish" contains ":sns:").
int sdkIdx = arn.indexOf(":aws-sdk:");
if (sdkIdx >= 0) {
invokeUniversalTarget(arn.substring(sdkIdx + ":aws-sdk:".length()), payload, region);
return;
}
String targetRegion = extractRegion(arn, region);
if (arn.contains(":sqs:")) {
String queueUrl = AwsArnUtils.arnToQueueUrl(arn, baseUrl);
sqsService.sendMessage(queueUrl, payload, 0, targetRegion);
String messageGroupId = target.getSqsParameters() != null
? target.getSqsParameters().getMessageGroupId() : null;
sqsService.sendMessage(queueUrl, payload, 0, messageGroupId, null, targetRegion);
LOG.debugv("Scheduler delivered to SQS: {0}", arn);
} else if (arn.contains(":lambda:") || arn.contains(":function:")) {
String fnName = arn.substring(arn.lastIndexOf(':') + 1);
@@ -77,6 +92,50 @@ public class ScheduleInvoker {
}
}
/**
* Dispatches an EventBridge Scheduler universal target ({@code aws-sdk:<service>:<action>}),
* reading the call parameters from the target's {@code Input} payload. Supports the
* common {@code sns:publish} and {@code sqs:sendMessage} actions; other actions are
* logged as unsupported.
*/
private void invokeUniversalTarget(String serviceAction, String input, String region) {
JsonNode params;
try {
params = objectMapper.readTree(input == null || input.isBlank() ? "{}" : input);
} catch (Exception e) {
LOG.warnv("Scheduler: universal target {0} has unparseable Input: {1}", serviceAction, e.getMessage());
return;
}
switch (serviceAction) {
case "sns:publish" -> {
String topicArn = text(params, "TopicArn");
String targetArn = text(params, "TargetArn");
String message = text(params, "Message");
String subject = text(params, "Subject");
String messageGroupId = text(params, "MessageGroupId");
String messageDeduplicationId = text(params, "MessageDeduplicationId");
String snsRegion = extractRegion(topicArn != null ? topicArn : targetArn, region);
snsService.publish(topicArn, targetArn, null, message, subject, null,
messageGroupId, messageDeduplicationId, snsRegion);
LOG.debugv("Scheduler delivered to SNS (universal target): {0}", topicArn);
}
case "sqs:sendMessage" -> {
String queueUrl = text(params, "QueueUrl");
String body = text(params, "MessageBody");
String messageGroupId = text(params, "MessageGroupId");
String messageDeduplicationId = text(params, "MessageDeduplicationId");
sqsService.sendMessage(queueUrl, body, 0, messageGroupId, messageDeduplicationId, region);
LOG.debugv("Scheduler delivered to SQS (universal target): {0}", queueUrl);
}
default -> LOG.warnv("Scheduler: unsupported universal target action: {0}", serviceAction);
}
}
private static String text(JsonNode node, String field) {
JsonNode value = node.get(field);
return value != null && !value.isNull() ? value.asText() : null;
}
private boolean isEventBridgePutEventsArn(String arn) {
return arn.contains(":events:") && arn.contains(":event-bus/");
}
@@ -105,6 +164,9 @@ public class ScheduleInvoker {
}
private static String extractRegion(String arn, String defaultRegion) {
if (arn == null) {
return defaultRegion;
}
String[] parts = arn.split(":");
return parts.length >= 4 && !parts[3].isEmpty() ? parts[3] : defaultRegion;
}
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.services.scheduler.model.RetryPolicy;
import io.github.hectorvent.floci.services.scheduler.model.Schedule;
import io.github.hectorvent.floci.services.scheduler.model.ScheduleGroup;
import io.github.hectorvent.floci.services.scheduler.model.ScheduleRequest;
import io.github.hectorvent.floci.services.scheduler.model.SqsParameters;
import io.github.hectorvent.floci.services.scheduler.model.Target;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
@@ -260,6 +261,12 @@ public class SchedulerController {
dlc.put("Arn", s.getTarget().getDeadLetterConfig().getArn());
t.put("DeadLetterConfig", dlc);
}
if (s.getTarget().getSqsParameters() != null
&& s.getTarget().getSqsParameters().getMessageGroupId() != null) {
Map<String, Object> sp = new HashMap<>();
sp.put("MessageGroupId", s.getTarget().getSqsParameters().getMessageGroupId());
t.put("SqsParameters", sp);
}
r.put("Target", t);
}
if (s.getDescription() != null) {
@@ -387,6 +394,14 @@ public class SchedulerController {
}
target.setDeadLetterConfig(dlc);
}
if (node.has("SqsParameters") && !node.get("SqsParameters").isNull()) {
JsonNode spNode = node.get("SqsParameters");
SqsParameters sp = new SqsParameters();
if (spNode.has("MessageGroupId") && !spNode.get("MessageGroupId").isNull()) {
sp.setMessageGroupId(spNode.get("MessageGroupId").asText());
}
target.setSqsParameters(sp);
}
return target;
}
@@ -0,0 +1,22 @@
package io.github.hectorvent.floci.services.scheduler.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
/**
* EventBridge Scheduler {@code Target.SqsParameters}. Carries the
* {@code MessageGroupId} required when the target is a FIFO SQS queue.
*/
@RegisterForReflection
public class SqsParameters {
private String messageGroupId;
public SqsParameters() {}
public SqsParameters(String messageGroupId) {
this.messageGroupId = messageGroupId;
}
public String getMessageGroupId() { return messageGroupId; }
public void setMessageGroupId(String messageGroupId) { this.messageGroupId = messageGroupId; }
}
@@ -10,6 +10,7 @@ public class Target {
private String input;
private RetryPolicy retryPolicy;
private DeadLetterConfig deadLetterConfig;
private SqsParameters sqsParameters;
public Target() {}
@@ -34,4 +35,7 @@ public class Target {
public DeadLetterConfig getDeadLetterConfig() { return deadLetterConfig; }
public void setDeadLetterConfig(DeadLetterConfig deadLetterConfig) { this.deadLetterConfig = deadLetterConfig; }
public SqsParameters getSqsParameters() { return sqsParameters; }
public void setSqsParameters(SqsParameters sqsParameters) { this.sqsParameters = sqsParameters; }
}