feat(pipes): validate ParallelizationFactor on Kinesis and DynamoDB sources (#3192)

* feat(pipes): validate ParallelizationFactor on Kinesis and DynamoDB sources

SourceParameters is stored as an opaque JsonNode, so ParallelizationFactor
already round-tripped through CreatePipe, UpdatePipe and DescribePipe with no
bounds applied at all. Apply the AWS constraints in validateSourceConfiguration,
which both the create and update paths already run:

- reject the field on a source its parameter block does not describe, for
  example KinesisStreamParameters.ParallelizationFactor on an SQS source
- require a numeric, then an integral value
- require a value in [1, 10], reported with the offending value

The tiering and message shape follow LambdaService.parseScalingConfig, which
applies the equivalent MaximumConcurrency bounds for SQS event source mappings.

The value is persisted and returned on the wire but not yet enforced: the poller
opens an iterator on a single hardcoded shard and delivers one batch at a time,
so there is no per-shard concurrency to scale. Record that on both iterator
initializers and in an enforcement-status note in the docs, matching how
ScalingConfig documents the same gap for Lambda.

* fix(pipes): reject a ParallelizationFactor wider than an int

asLong hands back the low 64 bits of a BigInteger, so a value such as
2^64 + 5 read as 5 and passed the [1, 10] bounds check: CreatePipe accepted
it over raw HTTP and persisted the original digits. Gate the bounds on
canConvertToInt and report the value with asText, so an oversized literal is
rejected and named in full. Real AWS rejects it too, the field being an int32.

Also correct the docs: ListPipes returns pipe summaries and omits
SourceParameters entirely, so only DescribePipe echoes the factor back.
This commit is contained in:
Danny authored and GitHub committed 2026-09-07 18:39:32 -04:00
1 parent 5864b013d2
commit 5fd89e27bc
6 files changed
+392 -3

No files matched your search

@@ -252,4 +252,89 @@ class PipesIntegrationTest {
.then()
.statusCode(400);
}
@Test
@Order(14)
void createPipeReturnsParallelizationFactorInResponse() {
given()
.contentType("application/json")
.body("""
{
"Source": "arn:aws:kinesis:us-east-1:000000000000:stream/pf-stream",
"Target": "arn:aws:sqs:us-east-1:000000000000:pf-target",
"RoleArn": "arn:aws:iam::000000000000:role/pipe-role",
"DesiredState": "STOPPED",
"SourceParameters": {
"KinesisStreamParameters": {
"StartingPosition": "TRIM_HORIZON",
"ParallelizationFactor": 4
}
}
}
""")
.when()
.post("/v1/pipes/pf-pipe")
.then()
.statusCode(200)
.body("SourceParameters.KinesisStreamParameters.ParallelizationFactor", equalTo(4));
given()
.contentType("application/json")
.when()
.get("/v1/pipes/pf-pipe")
.then()
.statusCode(200)
.body("SourceParameters.KinesisStreamParameters.ParallelizationFactor", equalTo(4));
given()
.contentType("application/json")
.when()
.delete("/v1/pipes/pf-pipe")
.then()
.statusCode(200);
}
@Test
@Order(15)
void createPipeParallelizationFactorOutOfRangeReturns400() {
given()
.contentType("application/json")
.body("""
{
"Source": "arn:aws:kinesis:us-east-1:000000000000:stream/pf-stream",
"Target": "arn:aws:sqs:us-east-1:000000000000:pf-target",
"RoleArn": "arn:aws:iam::000000000000:role/pipe-role",
"DesiredState": "STOPPED",
"SourceParameters": {
"KinesisStreamParameters": {"ParallelizationFactor": 11}
}
}
""")
.when()
.post("/v1/pipes/pf-invalid-pipe")
.then()
.statusCode(400);
}
@Test
@Order(16)
void createPipeParallelizationFactorOnSqsSourceReturns400() {
given()
.contentType("application/json")
.body("""
{
"Source": "arn:aws:sqs:us-east-1:000000000000:pf-source",
"Target": "arn:aws:sqs:us-east-1:000000000000:pf-target",
"RoleArn": "arn:aws:iam::000000000000:role/pipe-role",
"DesiredState": "STOPPED",
"SourceParameters": {
"KinesisStreamParameters": {"ParallelizationFactor": 4}
}
}
""")
.when()
.post("/v1/pipes/pf-wrong-source-pipe")
.then()
.statusCode(400);
}
}
@@ -1,5 +1,7 @@
package io.github.hectorvent.floci.services.pipes;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
@@ -21,6 +23,8 @@ import static org.mockito.Mockito.when;
class PipesServiceTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
private PipesService pipesService;
@BeforeEach
@@ -355,4 +359,159 @@ class PipesServiceTest {
pipesService.describePipe("region-pipe", "eu-west-1"));
assertEquals("NotFoundException", ex.getErrorCode());
}
@Test
void createPipeAcceptsParallelizationFactorOnKinesisSource() {
Pipe pipe = pipesService.createPipe("kinesis-pf-pipe",
"arn:aws:kinesis:us-east-1:000000000000:stream/events",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null,
sourceParameters("""
{"KinesisStreamParameters":{"StartingPosition":"TRIM_HORIZON","ParallelizationFactor":4}}"""),
null, null, null, "us-east-1");
assertEquals(4, pipe.getSourceParameters()
.path("KinesisStreamParameters").path("ParallelizationFactor").asInt());
}
@Test
void createPipeAcceptsParallelizationFactorOnDynamoDbStreamSource() {
Pipe pipe = pipesService.createPipe("ddb-pf-pipe",
"arn:aws:dynamodb:us-east-1:000000000000:table/orders/stream/2024-01-01T00:00:00.000",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null,
sourceParameters("""
{"DynamoDBStreamParameters":{"StartingPosition":"LATEST","ParallelizationFactor":10}}"""),
null, null, null, "us-east-1");
assertEquals(10, pipe.getSourceParameters()
.path("DynamoDBStreamParameters").path("ParallelizationFactor").asInt());
}
@Test
void createPipeRejectsParallelizationFactorAboveMaximum() {
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.createPipe("pf-too-high",
"arn:aws:kinesis:us-east-1:000000000000:stream/events",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null,
sourceParameters("""
{"KinesisStreamParameters":{"ParallelizationFactor":11}}"""),
null, null, null, "us-east-1"));
assertEquals("ValidationException", ex.getErrorCode());
assertTrue(ex.getMessage().contains("must be between 1 and 10"), ex.getMessage());
}
@Test
void createPipeRejectsParallelizationFactorBelowMinimum() {
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.createPipe("pf-too-low",
"arn:aws:kinesis:us-east-1:000000000000:stream/events",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null,
sourceParameters("""
{"KinesisStreamParameters":{"ParallelizationFactor":0}}"""),
null, null, null, "us-east-1"));
assertEquals("ValidationException", ex.getErrorCode());
assertTrue(ex.getMessage().contains("must be between 1 and 10"), ex.getMessage());
}
@Test
void createPipeRejectsFractionalParallelizationFactor() {
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.createPipe("pf-fractional",
"arn:aws:kinesis:us-east-1:000000000000:stream/events",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null,
sourceParameters("""
{"KinesisStreamParameters":{"ParallelizationFactor":2.5}}"""),
null, null, null, "us-east-1"));
assertEquals("ValidationException", ex.getErrorCode());
assertTrue(ex.getMessage().contains("must be an integer"), ex.getMessage());
}
@Test
void createPipeRejectsParallelizationFactorWiderThanAnInt() {
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.createPipe("pf-oversized",
"arn:aws:kinesis:us-east-1:000000000000:stream/events",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null,
sourceParameters("""
{"KinesisStreamParameters":{"ParallelizationFactor":18446744073709551621}}"""),
null, null, null, "us-east-1"));
assertEquals("ValidationException", ex.getErrorCode());
assertTrue(ex.getMessage().contains("18446744073709551621"), ex.getMessage());
}
@Test
void createPipeRejectsNonNumericParallelizationFactor() {
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.createPipe("pf-non-numeric",
"arn:aws:kinesis:us-east-1:000000000000:stream/events",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null,
sourceParameters("""
{"KinesisStreamParameters":{"ParallelizationFactor":"4"}}"""),
null, null, null, "us-east-1"));
assertEquals("ValidationException", ex.getErrorCode());
assertTrue(ex.getMessage().contains("must be a numeric value"), ex.getMessage());
}
@Test
void createPipeRejectsParallelizationFactorOnSqsSource() {
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.createPipe("pf-wrong-source",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null,
sourceParameters("""
{"KinesisStreamParameters":{"ParallelizationFactor":4}}"""),
null, null, null, "us-east-1"));
assertEquals("ValidationException", ex.getErrorCode());
assertTrue(ex.getMessage().contains("only supported for Kinesis stream sources"), ex.getMessage());
}
@Test
void updatePipeRejectsInvalidParallelizationFactor() {
pipesService.createPipe("pf-update-pipe",
"arn:aws:kinesis:us-east-1:000000000000:stream/events",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null,
sourceParameters("""
{"KinesisStreamParameters":{"ParallelizationFactor":2}}"""),
null, null, null, "us-east-1");
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.updatePipe("pf-update-pipe", null, null, null, null, null,
sourceParameters("""
{"KinesisStreamParameters":{"ParallelizationFactor":99}}"""),
null, null, "us-east-1"));
assertEquals("ValidationException", ex.getErrorCode());
assertTrue(ex.getMessage().contains("must be between 1 and 10"), ex.getMessage());
}
private static JsonNode sourceParameters(String json) {
try {
return MAPPER.readTree(json);
} catch (Exception e) {
throw new IllegalStateException("invalid test JSON: " + json, e);
}
}
}