feat(eventbridge): deliver events to Kinesis targets (#8561)

* feat(eventbridge): deliver events to Kinesis targets
* fix(eventbridge): preserve CloudFormation Kinesis partition key paths
* test(eventbridge): clean up Kinesis fixtures after teardown failures
* fix(eventbridge): match Kinesis partition key path delivery
This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-11-16 09:30:26 -04:00
1 parent bbc6e1b0a1
commit 0d6aa45d1f
8 files changed
+491 -3

No files matched your search

@@ -204,6 +204,10 @@ public class EventsCfnProvisioner implements CfnResourceProvisioner {
}
Target target = new Target(targetId, targetArn, input, inputPath);
target.setInputTransformer(InputTransformer.fromJson(resolved.path("InputTransformer")));
JsonNode kinesisParamsNode = resolved.path("KinesisParameters");
if (kinesisParamsNode.isObject()) {
target.setKinesisParameters(MAPPER.convertValue(kinesisParamsNode, Target.KinesisParameters.class));
}
JsonNode httpParamsNode = resolved.path("HttpParameters");
if (httpParamsNode.isObject()) {
target.setHttpParameters(MAPPER.convertValue(httpParamsNode, HttpParameters.class));
@@ -269,6 +269,11 @@ public class EventBridgeHandler {
);
target.setRoleArn(t.path("RoleArn").asText(null));
target.setInputTransformer(InputTransformer.fromJson(t.path("InputTransformer")));
JsonNode kinesisParamsNode = t.path("KinesisParameters");
if (kinesisParamsNode.isObject()) {
target.setKinesisParameters(
objectMapper.convertValue(kinesisParamsNode, Target.KinesisParameters.class));
}
JsonNode sqsParamsNode = t.path("SqsParameters");
if (!sqsParamsNode.isMissingNode() && sqsParamsNode.isObject()) {
String messageGroupId = sqsParamsNode.path("MessageGroupId").asText(null);
@@ -362,6 +367,9 @@ public class EventBridgeHandler {
transformerNode.put("InputTemplate", t.getInputTransformer().getInputTemplate());
}
}
if (t.getKinesisParameters() != null) {
node.set("KinesisParameters", objectMapper.valueToTree(t.getKinesisParameters()));
}
if (t.getSqsParameters() != null && t.getSqsParameters().getMessageGroupId() != null) {
node.putObject("SqsParameters").put("MessageGroupId", t.getSqsParameters().getMessageGroupId());
}
@@ -28,6 +28,7 @@ import io.floci.aws.services.eventbridge.model.RedshiftDataParameters;
import io.floci.aws.services.eventbridge.model.Target;
import io.floci.aws.services.firehose.FirehoseService;
import io.floci.aws.services.firehose.model.Record;
import io.floci.aws.services.kinesis.KinesisService;
import io.floci.aws.services.lambda.LambdaService;
import io.floci.aws.services.lambda.model.InvocationType;
import io.floci.aws.services.redshiftdata.RedshiftDataService;
@@ -84,6 +85,7 @@ public class EventBridgeInvoker {
private final SnsService snsService;
private final BatchService batchService;
private final FirehoseService firehoseService;
private final KinesisService kinesisService;
private final EventBridgeService eventBridgeService;
private final EcsService ecsService;
private final EcsJsonHandler ecsJsonHandler;
@@ -100,6 +102,19 @@ public class EventBridgeInvoker {
private final Map<String, RateWindow> rateWindows = new ConcurrentHashMap<>();
@Inject
public EventBridgeInvoker(LambdaService lambdaService, SqsService sqsService, SnsService snsService,
BatchService batchService, FirehoseService firehoseService, KinesisService kinesisService,
EventBridgeService eventBridgeService, EcsService ecsService,
EcsJsonHandler ecsJsonHandler, StepFunctionsService stepFunctionsService,
RedshiftDataService redshiftDataService, RedshiftTargetAuthorizer redshiftTargetAuthorizer,
ServiceRegistry serviceRegistry, RegionResolver regionResolver, ObjectMapper objectMapper,
EmulatorConfig config, AppSyncTargetInvoker appSyncTargetInvoker) {
this(lambdaService, sqsService, snsService, batchService, firehoseService, kinesisService, eventBridgeService,
ecsService, ecsJsonHandler, stepFunctionsService, redshiftDataService, redshiftTargetAuthorizer,
serviceRegistry, regionResolver, objectMapper, config,
apiDestinationClient(ContainerCaBundle.sslContext(config).orElse(null)), appSyncTargetInvoker);
}
public EventBridgeInvoker(LambdaService lambdaService, SqsService sqsService, SnsService snsService,
BatchService batchService, FirehoseService firehoseService,
EventBridgeService eventBridgeService, EcsService ecsService,
@@ -107,10 +122,9 @@ public class EventBridgeInvoker {
RedshiftDataService redshiftDataService, RedshiftTargetAuthorizer redshiftTargetAuthorizer,
ServiceRegistry serviceRegistry, RegionResolver regionResolver, ObjectMapper objectMapper,
EmulatorConfig config, AppSyncTargetInvoker appSyncTargetInvoker) {
this(lambdaService, sqsService, snsService, batchService, firehoseService, eventBridgeService,
this(lambdaService, sqsService, snsService, batchService, firehoseService, null, eventBridgeService,
ecsService, ecsJsonHandler, stepFunctionsService, redshiftDataService, redshiftTargetAuthorizer,
serviceRegistry, regionResolver, objectMapper, config,
apiDestinationClient(ContainerCaBundle.sslContext(config).orElse(null)), appSyncTargetInvoker);
serviceRegistry, regionResolver, objectMapper, config, appSyncTargetInvoker);
}
// The client API destinations are delivered with: sslContext, when given, adds the extra CAs in
@@ -171,11 +185,24 @@ public class EventBridgeInvoker {
RedshiftDataService redshiftDataService, RedshiftTargetAuthorizer redshiftTargetAuthorizer,
ServiceRegistry serviceRegistry, RegionResolver regionResolver, ObjectMapper objectMapper,
EmulatorConfig config, HttpClient httpClient, AppSyncTargetInvoker appSyncTargetInvoker) {
this(lambdaService, sqsService, snsService, batchService, firehoseService, null, eventBridgeService,
ecsService, ecsJsonHandler, stepFunctionsService, redshiftDataService, redshiftTargetAuthorizer,
serviceRegistry, regionResolver, objectMapper, config, httpClient, appSyncTargetInvoker);
}
private EventBridgeInvoker(LambdaService lambdaService, SqsService sqsService, SnsService snsService,
BatchService batchService, FirehoseService firehoseService, KinesisService kinesisService,
EventBridgeService eventBridgeService, EcsService ecsService,
EcsJsonHandler ecsJsonHandler, StepFunctionsService stepFunctionsService,
RedshiftDataService redshiftDataService, RedshiftTargetAuthorizer redshiftTargetAuthorizer,
ServiceRegistry serviceRegistry, RegionResolver regionResolver, ObjectMapper objectMapper,
EmulatorConfig config, HttpClient httpClient, AppSyncTargetInvoker appSyncTargetInvoker) {
this.lambdaService = lambdaService;
this.sqsService = sqsService;
this.snsService = snsService;
this.batchService = batchService;
this.firehoseService = firehoseService;
this.kinesisService = kinesisService;
this.eventBridgeService = eventBridgeService;
this.ecsService = ecsService;
this.ecsJsonHandler = ecsJsonHandler;
@@ -294,6 +321,28 @@ public class EventBridgeInvoker {
firehoseService.putRecord(streamArn.accountId(), streamArn.region(), streamName, record);
}
LOG.debugv("EventBridge delivered to Firehose: {0}", arn);
} else if (AwsArnUtils.isArnFor(arn, "kinesis")
&& AwsArnUtils.parse(arn).resource().startsWith("stream/")) {
if (kinesisService == null) {
throw new AwsException("ServiceNotAvailableException", "Kinesis delivery is not available.", 400);
}
AwsArnUtils.Arn streamArn = AwsArnUtils.parse(arn);
String partitionKey;
if (target.getKinesisParameters() == null) {
partitionKey = extractJsonPath("$.id", eventJson);
} else {
JsonNode selected = extractNode(target.getKinesisParameters().partitionKeyPath(), eventJson);
partitionKey = selected.isMissingNode() ? "{}" : selected.toString();
}
if (partitionKey == null || partitionKey.codePointCount(0, partitionKey.length()) < 1
|| partitionKey.codePointCount(0, partitionKey.length()) > 256) {
throw new AwsException("InvalidParameterException",
"EventBridge Kinesis partition key is missing or outside 1..256 characters.", 400);
}
String streamName = streamArn.resource().substring("stream/".length());
kinesisService.putRecordForAccount(streamArn.accountId(), streamName,
payload.getBytes(StandardCharsets.UTF_8), partitionKey, streamArn.region());
LOG.debugv("EventBridge delivered to Kinesis: {0}", arn);
} else if (AwsArnUtils.isArnFor(arn, "redshift")
|| AwsArnUtils.isArnFor(arn, "redshift-serverless")) {
deliverToRedshiftData(target, arn, eventJson, ruleArn);
@@ -654,6 +654,16 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
throw SmithyValidationErrors.validationException(violation);
}
}
Target.KinesisParameters kinesisParameters = target.getKinesisParameters();
if (kinesisParameters != null) {
String path = kinesisParameters.partitionKeyPath();
String field = "targets." + (i + 1) + ".member.kinesisParameters.partitionKeyPath";
String violation = path == null ? SmithyValidationErrors.notNull(field)
: SmithyValidationErrors.Violations.WITHOUT_VALUES.lengthOutOfRange(field, path, 0, 256);
if (violation != null) {
throw SmithyValidationErrors.validationException(violation);
}
}
Integer attempts = target.getRetryPolicy() != null ? target.getRetryPolicy().maximumRetryAttempts() : null;
Integer age = target.getRetryPolicy() != null ? target.getRetryPolicy().maximumEventAgeInSeconds() : null;
String arn = target.getDeadLetterConfig() != null ? target.getDeadLetterConfig().arn() : null;
@@ -15,6 +15,7 @@ public class Target {
private String input;
private String inputPath;
private InputTransformer inputTransformer;
private KinesisParameters kinesisParameters;
private SqsParameters sqsParameters;
private BatchParameters batchParameters;
private EcsParameters ecsParameters;
@@ -51,6 +52,11 @@ public class Target {
public InputTransformer getInputTransformer() { return inputTransformer; }
public void setInputTransformer(InputTransformer inputTransformer) { this.inputTransformer = inputTransformer; }
public KinesisParameters getKinesisParameters() { return kinesisParameters; }
public void setKinesisParameters(KinesisParameters kinesisParameters) {
this.kinesisParameters = kinesisParameters;
}
public SqsParameters getSqsParameters() { return sqsParameters; }
public void setSqsParameters(SqsParameters sqsParameters) { this.sqsParameters = sqsParameters; }
@@ -77,6 +83,11 @@ public class Target {
public AppSyncParameters getAppSyncParameters() { return appSyncParameters; }
public void setAppSyncParameters(AppSyncParameters appSyncParameters) { this.appSyncParameters = appSyncParameters; }
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public record KinesisParameters(@JsonProperty("PartitionKeyPath") String partitionKeyPath) {}
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)