fix(pipes): send an SQS target's MessageGroupId and MessageDeduplicationId (#9178)

A pipe with an SQS queue target ignored SqsQueueParameters, so a FIFO queue target failed every
delivery for want of a group id. MessageGroupId and MessageDeduplicationId now reach SendMessage,
each a literal or a JSON path read off the event before the InputTemplate renders, as the event bus
target already does for Source and DetailType. A number becomes its text and an object its compact
JSON, and a path that names nothing fails the delivery.

CreatePipe and UpdatePipe check them as AWS does: a target whose queue name ends in .fifo needs
SqsQueueParameters and a MessageGroupId, MessageDeduplicationId is refused on a standard queue, and
a value that starts with $. but is not a valid JSON path is refused. The errors are reported
together, in AWS's order, as a ValidationException with fieldList; UpdatePipe checks against the
stored target when the request leaves it out.

Part of #7481.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-22 01:12:40 -04:00
1 parent 11b66161cd
commit 48b95fc8c7
7 files changed
+453 -19

No files matched your search

@@ -70,9 +70,7 @@ public class PipesController {
return Response.ok(buildPipeResponse(pipe)).build();
} catch (AwsException e) {
return Response.status(e.getHttpStatus())
.entity(new AwsErrorResponse(e.getErrorCode(), e.getMessage()))
.build();
throw e;
} catch (Exception e) {
LOG.errorv("Error creating pipe: {0}", e.getMessage());
return Response.status(500)
@@ -119,9 +117,7 @@ public class PipesController {
return Response.ok(buildPipeResponse(pipe)).build();
} catch (AwsException e) {
return Response.status(e.getHttpStatus())
.entity(new AwsErrorResponse(e.getErrorCode(), e.getMessage()))
.build();
throw e;
} catch (Exception e) {
LOG.errorv("Error updating pipe: {0}", e.getMessage());
return Response.status(500)
@@ -2,7 +2,10 @@ package io.floci.aws.services.pipes;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.MissingNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.RegionResolver;
@@ -23,11 +26,13 @@ import org.jboss.logging.Logger;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ApplicationScoped
@@ -41,6 +46,9 @@ public class PipesService implements TagHandler, ResourceProvider {
private static final int MAX_REDSHIFT_SQLS = 40;
private static final int MAX_REDSHIFT_SQL_LENGTH = 100_000;
// CreatePipe refuses a target parameter that starts with $. and does not match this.
private static final Pattern TARGET_PARAMETER_PATH = Pattern.compile("\\$(?:\\.[\\w/-]+|\\[(?:\\d+|\\*)])+");
private final StorageBackend<String, Pipe> storage;
private final RegionResolver regionResolver;
private final PipesPoller poller;
@@ -354,15 +362,20 @@ public class PipesService implements TagHandler, ResourceProvider {
"Resource " + arn + " does not exist.", 404));
}
private void validateTargetConfiguration(String target, JsonNode targetParameters) {
if (AwsArnUtils.isArnFor(target, "sqs")) {
validateSqsTarget(target, targetParameters);
} else if (PipesTargetInvoker.isRedshiftTarget(target)) {
validateRedshiftTarget(targetParameters);
}
}
/**
* A Redshift target runs its {@code Sqls} as one BatchExecuteStatement, which the PipeTargetRedshiftDataParameters
* reference makes required together with {@code Database}, with 1 to 40 statements of at most 100,000
* characters each.
*/
private void validateTargetConfiguration(String target, JsonNode targetParameters) {
if (!PipesTargetInvoker.isRedshiftTarget(target)) {
return;
}
private void validateRedshiftTarget(JsonNode targetParameters) {
JsonNode parameters = targetParameters == null
? MissingNode.getInstance() : targetParameters.path("RedshiftDataParameters");
if (!parameters.path("Database").isTextual() || parameters.path("Database").asText().isBlank()) {
@@ -384,6 +397,64 @@ public class PipesService implements TagHandler, ResourceProvider {
}
}
private void validateSqsTarget(String target, JsonNode targetParameters) {
boolean fifo = AwsArnUtils.resourceIfArnFor(target, "sqs").orElse("").endsWith(".fifo");
JsonNode sqsParameters = targetParameters == null
? MissingNode.getInstance() : targetParameters.path("SqsQueueParameters");
if (sqsParameters.isMissingNode() || sqsParameters.isNull()) {
if (fifo) {
throw validationFields(List.of(new ValidationField(
"TargetParameters.SqsQueueParameters", "Missing required target parameter.")));
}
return;
}
String groupId = PipesTargetInvoker.text(sqsParameters, "MessageGroupId");
String dedupId = PipesTargetInvoker.text(sqsParameters, "MessageDeduplicationId");
List<ValidationField> errors = new ArrayList<>();
if (groupId != null && isInvalidDynamicPath(groupId)) {
errors.add(new ValidationField("MessageGroupId", invalidPathMessage(groupId)));
}
if (dedupId != null && isInvalidDynamicPath(dedupId)) {
errors.add(new ValidationField("MessageDeduplicationId", invalidPathMessage(dedupId)));
}
if (dedupId != null && !fifo) {
errors.add(new ValidationField("MessageDeduplicationId",
"Parameter only applies to FIFO (first-in-first-out) queues."));
}
if (fifo && groupId == null) {
errors.add(new ValidationField("MessageGroupId",
"MessageGroupId is required for FIFO (first-in-first-out) queues."));
}
if (!errors.isEmpty()) {
throw validationFields(errors);
}
}
private static boolean isInvalidDynamicPath(String value) {
return value.startsWith("$.") && !TARGET_PARAMETER_PATH.matcher(value).matches();
}
private static String invalidPathMessage(String value) {
return "Invalid JSON path " + value + " provided in the service target parameters.";
}
private static AwsException validationFields(List<ValidationField> errors) {
ArrayNode validationErrorFields = JsonNodeFactory.instance.arrayNode();
List<Map<String, String>> fieldList = new ArrayList<>();
for (ValidationField error : errors) {
validationErrorFields.addObject().put("Name", error.name()).put("Message", error.message());
Map<String, String> field = new LinkedHashMap<>();
field.put("name", error.name());
field.put("message", error.message());
fieldList.add(field);
}
ObjectNode message = JsonNodeFactory.instance.objectNode();
message.set("ValidationErrorFields", validationErrorFields);
return new AwsException("ValidationException", message.toString(), 400, Map.of("fieldList", fieldList));
}
private record ValidationField(String name, String message) {}
private void validateSourceConfiguration(String source, JsonNode sourceParameters) {
if (source == null) {
return;
@@ -104,7 +104,7 @@ public class PipesTargetInvoker {
if (targetArn.contains(":lambda:") || targetArn.contains(":function:")) {
invokeLambda(targetArn, payload, region);
} else if (targetArn.contains(":sqs:")) {
invokeSqs(targetArn, payload, region);
invokeSqs(targetArn, payload, region, tp, event);
} else if (targetArn.contains(":sns:")) {
invokeSns(targetArn, payload, region);
} else if (targetArn.contains(":events:")) {
@@ -198,9 +198,14 @@ public class PipesTargetInvoker {
return fi >= 0 ? ref.substring(fi + ":function:".length()) : ref;
}
private void invokeSqs(String arn, String payload, String region) {
private void invokeSqs(String arn, String payload, String region, JsonNode tp, String event) {
String queueUrl = AwsArnUtils.arnToQueueUrl(arn, baseUrl);
sqsService.sendMessage(queueUrl, payload, 0, region);
JsonNode sqsParams = tp == null ? MissingNode.getInstance() : tp.path("SqsQueueParameters");
String groupId = resolveDynamicParameter(text(sqsParams, "MessageGroupId"), event,
"target parameter MessageGroupId");
String dedupId = resolveDynamicParameter(text(sqsParams, "MessageDeduplicationId"), event,
"target parameter MessageDeduplicationId");
sqsService.sendMessage(queueUrl, payload, 0, groupId, dedupId, region);
LOG.debugv("Pipe delivered to SQS: {0}", arn);
}
@@ -290,7 +295,7 @@ public class PipesTargetInvoker {
LOG.debugv("Pipe delivered to Redshift Data API: {0}", targetArn);
}
private static String text(JsonNode parent, String field) {
static String text(JsonNode parent, String field) {
JsonNode node = parent.path(field);
return node.isTextual() ? node.asText() : null;
}