All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.com.steamstreet.aws.test.DynamoEventBridgePipe.kt Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package com.steamstreet.aws.test

import aws.sdk.kotlin.services.eventbridge.EventBridgeClient
import aws.sdk.kotlin.services.eventbridge.model.PutEventsRequestEntry
import aws.sdk.kotlin.services.eventbridge.putEvents
import com.steamstreet.dynamokt.DynamoStreamEvent
import kotlinx.serialization.json.Json

/**
 * Returns a StreamProcessorFunction that can be used to pipe stream events
 * to an EventBridge bus.
 *
 * Pass this to the DynamoStreamRunner constructor to pipe data to
 * the provided EventBridge client (which will typically be EventBridgeMock).
 */
public fun dynamoPipe(
    eventBridge: EventBridgeClient,
    eventBusArn: String,
    detailType: String,
    source: String
): StreamProcessorFunction {
    suspend fun streamProcessor(event: DynamoStreamEvent) {
        eventBridge.putEvents {
            entries = listOf(
                PutEventsRequestEntry {
                    eventBusName = (eventBusArn.substringAfterLast(":event-bus/"))
                    detail = (Json.encodeToString(DynamoStreamEvent.serializer(), event))
                    this.detailType = detailType
                    this.source = source
                }
            )
        }
    }
    return ::streamProcessor
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy