This is an AWS CDK Construct that will listen for any EventBridge Bus and Rule and forward that event through a websocket.
Get setup in seconds and as easy as 7 lines of code.
You may want to use tools like Postman Websockets or websocat to see and debug what events are being fired through your event bus.
This uses AWS ApiGateway, DynamoDB (to store connections) and Lambda.
npm install --save cdk-eventbridge-socket
import * as cdk from '@aws-cdk/core';
import { EventBridgeWebSocket } from 'cdk-eventbridge-socket';
export class EventbridgeWebhooksStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new EventBridgeWebSocket(this, 'sockets', {
bus: 'your-event-bus-name',
// This example shows how to listen for all events
eventPattern: {
account: ['your_account_id'],
},
stage: 'dev',
});
}
}
When using the cdk-eventbridge-socket
the new websocket url will be output on your terminal.
There are only a few properties you have to set bus
, eventPattern
and stage
.
You can listen to any EventBridge source/pattern you like, just replace the eventPattern
with what you want to listen to.
new EventBridgeWebSocket(this, 'sockets', {
bus: 'your-event-bus-name',
// Listens for all UserCreated events
eventPattern: {
detailType: ['UserCreated'],
},
stage: 'dev',
});
new EventBridgeWebSocket(this, 'sockets', {
bus: 'your-event-bus-name',
// Listens for all events on source
eventPattern: {
source: ['myapp.users'],
},
stage: 'dev',
});
You can find more here on the AWS documentation
If you have any questions, features or issues please raise any issue or pull requests you like. I will try my best to get back to you.
MIT.