Skip to main content

Overview

The EventBridgeBus construct creates an Amazon EventBridge custom event bus. Route events between microservices with content-based filtering rules.

Import

import { EventBridgeBus } from "@fjall/components-infrastructure";

Basic Usage

const bus = new EventBridgeBus(scope, "AppEvents", {});

Using the Messaging Factory

The recommended way to add EventBridge to a Fjall application is through the MessagingFactory:
import { MessagingFactory } from "@fjall/components-infrastructure";

const events = app.addMessaging(
  MessagingFactory.build("AppEvents", {
    type: "eventBus",
  }),
);

Properties

PropertyTypeDefaultDescription
eventBusNamestringAuto-generatedEvent bus name
descriptionstringEventBus <appName> — Fjall app event busEvent bus description
removalPolicy"DESTROY" | "RETAIN""RETAIN" in production, else "DESTROY"What happens on stack deletion

Methods

MethodReturnsDescription
getEventBusArn()stringEvent bus ARN
getEventBusName()stringEvent bus name
getEventBus()IEventBusCDK EventBus construct
grantPutEventsTo(grantee)GrantGrant permission to publish events

Examples

Custom Event Bus

const domainEvents = app.addMessaging(
  MessagingFactory.build("DomainEvents", {
    type: "eventBus",
  }),
);

domainEvents.grantPutEventsTo(apiService);

Event Routing with Rules

Add rules to route events to specific targets:
import { Rule } from "aws-cdk-lib/aws-events";
import { LambdaFunction } from "aws-cdk-lib/aws-events-targets";

const bus = app.addMessaging(
  MessagingFactory.build("AppEvents", {
    type: "eventBus",
  }),
);

// Route order events to a processing Lambda
new Rule(scope, "OrderRule", {
  eventBus: bus.getEventBus(),
  eventPattern: {
    source: ["orders"],
    detailType: ["OrderCreated"],
  },
  targets: [new LambdaFunction(processorLambda.getFunction())],
});

CloudFormation Outputs

OutputDescription
{id}EventBusArnEvent bus ARN
{id}EventBusNameEvent bus name

Next Steps

Messaging Factory

Create messaging resources via the factory pattern

Lambda Function

Process events with Lambda

SQS Queue

Buffer and decouple work with a managed queue

SNS Topic

Fan out notifications to multiple subscribers