> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fjall.io/llms.txt
> Use this file to discover all available pages before exploring further.

# EventBridge Bus

> Route events between AWS services with a Fjall EventBridge custom event bus and content-based filtering rules.

## Overview

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

## Import

```typescript theme={null}
import { EventBridgeBus } from "@fjall/components-infrastructure";
```

## Basic Usage

```typescript theme={null}
const bus = new EventBridgeBus(scope, "AppEvents", {});
```

## Using the Messaging Factory

The recommended way to add EventBridge to a Fjall application is through the `MessagingFactory`:

```typescript theme={null}
import { MessagingFactory } from "@fjall/components-infrastructure";

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

## Properties

| Property        | Type                    | Default                                    | Description                    |
| --------------- | ----------------------- | ------------------------------------------ | ------------------------------ |
| `eventBusName`  | `string`                | Auto-generated                             | Event bus name                 |
| `description`   | `string`                | `EventBus <appName> — Fjall app event bus` | Event bus description          |
| `removalPolicy` | `"DESTROY" \| "RETAIN"` | `"RETAIN"` in production, else `"DESTROY"` | What happens on stack deletion |

## Methods

| Method                      | Returns     | Description                        |
| --------------------------- | ----------- | ---------------------------------- |
| `getEventBusArn()`          | `string`    | Event bus ARN                      |
| `getEventBusName()`         | `string`    | Event bus name                     |
| `getEventBus()`             | `IEventBus` | CDK EventBus construct             |
| `grantPutEventsTo(grantee)` | `Grant`     | Grant permission to publish events |

## Examples

### Custom Event Bus

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

domainEvents.grantPutEventsTo(apiService);
```

### Event Routing with Rules

Add rules to route events to specific targets:

```typescript theme={null}
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

| Output             | Description    |
| ------------------ | -------------- |
| `{id}EventBusArn`  | Event bus ARN  |
| `{id}EventBusName` | Event bus name |

## Next Steps

<CardGroup cols={2}>
  <Card title="Messaging Factory" icon="industry" href="/patterns/messaging-factory">
    Create messaging resources via the factory pattern
  </Card>

  <Card title="Lambda Function" icon="bolt" href="/resources/compute/lambda-function">
    Process events with Lambda
  </Card>

  <Card title="SQS Queue" icon="layer-group" href="/resources/messaging/sqs-queue">
    Buffer and decouple work with a managed queue
  </Card>

  <Card title="SNS Topic" icon="bullhorn" href="/resources/messaging/sns-topic">
    Fan out notifications to multiple subscribers
  </Card>
</CardGroup>
