When setting up rules for the `EventBus` how do I ...
# sst
j
When setting up rules for the
EventBus
how do I point to the Default event bus? I've been trying to set up a subscriber to all dynamoDB events but it never gets hit and I'm assuming that's because the events are being fired onto the default bus.
f
Copy code
import * as events from "aws-cdk-lib/aws-events";

new EventBus(this, "Bus", {
  eventBridgeEventBus: events.EventBus.fromEventBusName(
    this, "ImportedBus", "default"
  ),
  rules: {
    ...
  },
});
j
Thanks @Frank, am I correct in thinking that the DynamoDB events would go to the default, or when I define the Table, can I define the bus I want the events onto?
f
What events are you expecting?
j
I'm trying to use the events from dynamo to populate downstream non-production stores (dev, reporting etc). I have this rule:
Copy code
crossPlatformPopulator: {
            eventPattern: {
              source: ['aws.dynamodb'],
            },
            targets: ['src/crossPlatformPopulator.handler']
          }
and the handler just console.log's the event details. I was hoping that the create, update and delete events would land here but it gets nothing, which makes me think it was the default bus issue
f
I haven’t used the DynamoDB with EventBus. My guess is that when a table gets created/removed, that event gets sent to the default bus. But to listen for items created/update/removed in a able, you’d need to setup a DynamoDB stream (simpler/cheaper) or Kinesis stream (more scalable) - https://docs.serverless-stack.com/constructs/Table#enabling-dynamodb-streams
Serverless experts in this slack, please correct me if i’m wrong 😂
a
No, the events that you want to capture are table level events and not service level events. The default bus is to monitor service level events. While you could use the putEvents API and send the event to the default event bus I’d recommend against it. What I do is for every application, I maintain an EventBus that deals with the custom application specific events. As @Frank suggested, dynamodb streams to a consumer lambda to EventBridge would be the appropriate way to attempt this if this needs not to be realtime. The lambda subscribed to the dynamodb stream just needs to create the EventBridge events and then across the application you could wire some consumers that process those events. If this needs to be in sync I’d use a SQS FIFO queue. Hope this helps. Also, you can subscribe to the default bus and trigger custom events to your bus for more control and to maintain audit trails, logs, etc.
f
Haha I knew there are some serious aws experts in this community