# EventBridge Custom Event Bus

Source: /aws/services/eventbridgev2/

## Introduction

The EventBridge Custom Event Bus is an event bus that retains the events it receives and delivers them to subscribers, each with its own filters, transformer, and target.
See [What is the EventBridge Custom Event Bus](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-what-is.html) for an overview of the service and how it differs from the classic event bus described on the [EventBridge](/aws/services/events/) page.

LocalStack lets you use the Custom Event Bus APIs in your local environment to create event buses, subscribers, and event sources, publish events, replay retained events, and share buses across accounts.
The supported APIs are available on the [API coverage section](#api-coverage), which provides information on the extent of the Custom Event Bus integration with LocalStack.

## Getting started

This guide is designed for users new to the Custom Event Bus and assumes basic knowledge of the AWS CLI and our [`lstk aws`](/aws/developer-tools/running-localstack/lstk/cloud-and-iac-commands/#aws) command.

:::note
The AWS CLI exposes the Custom Event Bus as `aws eventsv2` starting with AWS CLI version 2.37.3.
Earlier versions and AWS CLI version 1 don't have the `eventsv2` command, so make sure `lstk aws` runs a recent AWS CLI version 2.
:::

Start your LocalStack container using your preferred method.
We will demonstrate how to create an event bus, an SQS queue, a delivery role, and a subscriber with a filter, and how to publish events and receive the matching ones.

### Create an event bus

Create an event bus with the [`CreateEventBus`](https://docs.aws.amazon.com/cli/latest/reference/eventsv2/create-event-bus.html) API:

```bash
lstk aws eventsv2 create-event-bus --name orders-bus
```

```bash title="Output"
{
    "EventBusArn": "arn:aws:events:us-east-1:000000000000:event-busv2/orders-bus/umsn1mzdebj8ynyo3i9hphbdq",
    "Name": "orders-bus",
    "StorageConfiguration": {
        "RetentionPeriodInDays": 1,
        "RetentionWindowStartTime": "2026-11-04T20:34:48.019616+01:00"
    },
    "State": "CREATING",
    "CreationTime": "2026-11-04T20:34:48.019616+01:00"
}
```

The bus keeps events for one day by default.
Set `--storage-configuration RetentionPeriodInDays=<days>` to keep them for up to 365 days.
Every bus gets an ARN with a unique id, so a bus that you delete and create again under the same name has a new ARN.
As on AWS, you can create up to 5 event buses per account and region.

The bus moves to the `ACTIVE` state once it is ready:

```bash
lstk aws eventsv2 describe-event-bus \
    --event-bus-arn arn:aws:events:us-east-1:000000000000:event-busv2/orders-bus/umsn1mzdebj8ynyo3i9hphbdq \
    --query State
```

```bash title="Output"
"ACTIVE"
```

### Create an SQS queue

Create the queue that receives the events:

```bash
lstk aws sqs create-queue --queue-name orders-queue
```

```bash title="Output"
{
    "QueueUrl": "http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/orders-queue"
}
```

### Create a delivery role

A subscriber delivers events with a delivery role in its own account, which EventBridge assumes.
Create a trust policy that allows EventBridge to assume the role:

```json title="trust-policy.json" showLineNumbers
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "Service": "events.amazonaws.com" },
      "Action": "sts:AssumeRole"
    }
  ]
}
```

Create the role and allow it to send messages to the queue:

```bash
lstk aws iam create-role \
    --role-name orders-delivery-role \
    --assume-role-policy-document file://trust-policy.json \
    --query Role.Arn
lstk aws iam put-role-policy \
    --role-name orders-delivery-role \
    --policy-name send-to-queue \
    --policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"sqs:SendMessage","Resource":"arn:aws:sqs:us-east-1:000000000000:orders-queue"}]}'
```

```bash title="Output"
"arn:aws:iam::000000000000:role/orders-delivery-role"
```

### Create a subscriber

Create a filter that matches `OrderPlaced` events with an amount greater than 100:

```json title="filter-configuration.json" showLineNumbers
{
  "Filters": [
    {
      "Scope": "DATA",
      "Pattern": "{\"detail-type\": [\"OrderPlaced\"], \"detail\": {\"amount\": [{\"numeric\": [\">\", 100]}]}}"
    }
  ]
}
```

Create a subscriber that delivers the matching events to the queue:

```bash
lstk aws eventsv2 create-subscriber \
    --name large-orders \
    --event-bus-arn arn:aws:events:us-east-1:000000000000:event-busv2/orders-bus/umsn1mzdebj8ynyo3i9hphbdq \
    --invoke-configuration TargetArn=arn:aws:sqs:us-east-1:000000000000:orders-queue,RoleArn=arn:aws:iam::000000000000:role/orders-delivery-role \
    --filter-configuration file://filter-configuration.json
```

```bash title="Output"
{
    "SubscriberArn": "arn:aws:events:us-east-1:000000000000:subscriber/large-orders/avf41lgwcg1a0yphcqquygj5p",
    "Name": "large-orders",
    "EventBusArn": "arn:aws:events:us-east-1:000000000000:event-busv2/orders-bus/umsn1mzdebj8ynyo3i9hphbdq",
    "Type": "UNORDERED",
    "StartingPosition": "LATEST",
    "State": "RUNNING",
    "CreationTime": "2026-11-04T20:35:10.276857+01:00"
}
```

The subscriber starts at the `LATEST` position, so it receives the events published after its creation.

### Publish events

Create a file with two orders, one above and one below the amount in the filter:

```json title="events.json" showLineNumbers
[
  {
    "Source": "com.example.orders",
    "DetailType": "OrderPlaced",
    "Detail": "{\"orderId\": \"1001\", \"amount\": 250}"
  },
  {
    "Source": "com.example.orders",
    "DetailType": "OrderPlaced",
    "Detail": "{\"orderId\": \"1002\", \"amount\": 20}"
  }
]
```

Publish them with the `PutEvents` API:

```bash
lstk aws eventsv2 put-events \
    --event-bus-arn arn:aws:events:us-east-1:000000000000:event-busv2/orders-bus/umsn1mzdebj8ynyo3i9hphbdq \
    --entries file://events.json
```

```bash title="Output"
{
    "FailedEntryCount": 0,
    "Entries": [
        {
            "EventId": "42f2b910-fa41-4e3c-88f2-0357603024b2",
            "SequenceNumber": "10000000000000003000",
            "SuccessCode": "PUBLISHED"
        },
        {
            "EventId": "c348603e-1e30-48c6-b862-f60e38417bd4",
            "SequenceNumber": "10000000000000003001",
            "SuccessCode": "PUBLISHED"
        }
    ]
}
```

Every event gets a sequence number on the bus.
As on AWS, the `EventId` that `PutEvents` returns is the event's `aws:EventId` system metadata, not the `id` of the delivered event.

### Receive the event

Receive the messages from the queue:

```bash
lstk aws sqs receive-message \
    --queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/orders-queue \
    --max-number-of-messages 10 \
    --wait-time-seconds 5
```

```bash title="Output"
{
    "Messages": [
        {
            "MessageId": "9d142381-23ee-400e-a6e7-a3e46a2aff4d",
            "ReceiptHandle": "Yzc2ZDI5N2QtNmE0ZC00YTljLTg1YTUtNDk4MTM5YzA0ZjM1IGFybjphd3M6c3FzOnVzLWVhc3QtMTowMDAwMDAwMDAwMDA6b3JkZXJzLXF1ZXVlIDlkMTQyMzgxLTIzZWUtNDAwZS1hNmU3LWEzZTQ2YTJhZmY0ZCAxNzkzODIwOTE4LjA1MDc2NTg=",
            "MD5OfBody": "1819980d0076750d69d443f8d4848703",
            "Body": "{\"version\":\"0\",\"id\":\"1401d847-110a-4fad-9ec9-8e57bbdb5efe\",\"detail-type\":\"OrderPlaced\",\"source\":\"com.example.orders\",\"account\":\"000000000000\",\"time\":\"2026-11-04T19:35:16Z\",\"region\":\"us-east-1\",\"resources\":[],\"detail\":{\"orderId\":\"1001\",\"amount\":250}}"
        }
    ]
}
```

Only the order with an amount of 250 matches the filter.
An SQS target receives one message per event.

## Supported features

LocalStack supports the following Custom Event Bus features.
See the linked AWS documentation for how they work.

- [Subscribers](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-subscribers.html), unordered or FIFO, with batching.
- [Filters](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-filtering.html) on the event data, metadata, and system metadata.
- [Transformers](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-transform.html) (`RAW`, `WITH_METADATA`, and `JSONATA`), and `{% %}` JSONata expressions in target parameters.
- [Retries and dead-letter queues](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-retry.html).
- [Replay](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-replay.html) from the oldest retained event or from a point in time, and stopping and resuming subscribers.
- Publishing with `PutEvents` and `PutRawEvents`, with deduplication, and raw events in JSON, binary, or Avro format.
- [Event sources](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-event-sources.html) for AWS service events.
- [Delivery logs](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-observability.html) through CloudWatch Logs vended log delivery.
- Resource policies, [sharing buses](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-sharing.html) with other accounts through AWS RAM, and revoking other accounts' subscribers and event sources with `RevokeResource`.

## Supported targets

LocalStack supports the following subscriber targets:

- SQS standard and FIFO queues.
- Lambda functions, with the `EVENT` and `REQUEST_RESPONSE` invocation types, qualifiers, and durable functions.
- Step Functions state machines, with asynchronous executions and synchronous executions of Express workflows.
- SNS topics.
- Kinesis data streams.
- Firehose streams.
- API Gateway REST APIs.
- API destinations, with basic, API key, and OAuth client credentials connections.
- Another Custom Event Bus.
- A classic EventBridge event bus.
- [Universal targets](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-universal-targets.html), which call an AWS API action with the event as input.

## Avro events

`PutRawEvents` decodes Avro events in the AWS Glue wire format, using the [Glue Schema Registry](/aws/services/glue/#schema-registry) that you pass with `--schema-registry-configuration`.
LocalStack caches the schema versions it looks up for 300 seconds, including failed lookups.
Set [`EVENTBRIDGEV2_SCHEMA_CACHE_TTL`](/aws/customization/configuration-options/#eventbridge) to change the duration, or to `0` to look up the schema for every event.

## Event sources

LocalStack implements an [event source](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-event-sources.html) as a managed rule on the classic default event bus of your account, which forwards the matching events to the Custom Event Bus unchanged.
Any event that a LocalStack service publishes to the default event bus can be forwarded.

Create a bucket and turn on its [EventBridge notifications](https://docs.aws.amazon.com/AmazonS3/latest/userguide/EventBridge.html):

```bash
lstk aws s3api create-bucket --bucket orders-invoices
lstk aws s3api put-bucket-notification-configuration \
    --bucket orders-invoices \
    --notification-configuration '{"EventBridgeConfiguration": {}}'
```

Create an event source that forwards the bucket's `Object Created` events:

```bash
lstk aws eventsv2 create-event-source \
    --name invoices-source \
    --event-bus-arn arn:aws:events:us-east-1:000000000000:event-busv2/orders-bus/umsn1mzdebj8ynyo3i9hphbdq \
    --configuration '{"AwsServiceEventsConfiguration": {"AwsService": "aws.s3", "Pattern": "{\"detail-type\": [\"Object Created\"], \"detail\": {\"bucket\": {\"name\": [\"orders-invoices\"]}}}"}}'
```

```bash title="Output"
{
    "EventSourceArn": "arn:aws:events:us-east-1:000000000000:event-sourcev2/aws.service/invoices-source/5cq6ljbd6m2pox7nf9fs1k5jg",
    "Name": "invoices-source",
    "EventBusArn": "arn:aws:events:us-east-1:000000000000:event-busv2/orders-bus/umsn1mzdebj8ynyo3i9hphbdq",
    "State": "ACTIVE",
    "CreationTime": "2026-11-04T20:56:11.221049+01:00"
}
```

Upload an object to the bucket:

```bash
lstk aws s3 cp invoice-1007.txt s3://orders-invoices/invoice-1007.txt
```

The subscribers of the bus receive the S3 event, for example the `orders-replay` subscriber, which has no filter:

```bash
lstk aws sqs receive-message \
    --queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/orders-replay-queue \
    --max-number-of-messages 10 \
    --wait-time-seconds 5 \
    --query 'Messages[].Body'
```

```bash title="Output"
[
    "{\"version\":\"0\",\"id\":\"c74479fa-8671-4efd-97d6-24dfdf97b7ab\",\"detail-type\":\"Object Created\",\"source\":\"aws.s3\",\"account\":\"000000000000\",\"time\":\"2026-11-04T19:56:11Z\",\"region\":\"us-east-1\",\"resources\":[\"arn:aws:s3:::orders-invoices\"],\"detail\":{\"version\":\"0\",\"event-version\":\"1.2\",\"bucket\":{\"name\":\"orders-invoices\"},\"object\":{\"key\":\"invoice-1007.txt\",\"size\":3,\"etag\":\"764efa883dda1e11db47671c4a3bbd9e\",\"sequencer\":\"006AEB8DDB00000000\"},\"request-id\":\"99255287-4fe4-4898-96ab-6a89c1eb5e4f\",\"requester\":\"000000000000\",\"source-ip-address\":\"127.0.0.1\",\"reason\":\"PutObject\"}}"
]
```

## Logging

Subscribers deliver their logs to CloudWatch Logs through [vended log delivery](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-observability.html), with the subscriber as the delivery source.
Turn on logging for the `large-orders` subscriber, and create a log group:

```bash
lstk aws eventsv2 update-subscriber \
    --subscriber-arn arn:aws:events:us-east-1:000000000000:subscriber/large-orders/avf41lgwcg1a0yphcqquygj5p \
    --log-configuration Level=INFO,IncludePayload=FULL
lstk aws logs create-log-group --log-group-name /aws/vendedlogs/large-orders
```

Create a delivery source for the subscriber:

```bash
lstk aws logs put-delivery-source \
    --name large-orders-logs \
    --resource-arn arn:aws:events:us-east-1:000000000000:subscriber/large-orders/avf41lgwcg1a0yphcqquygj5p \
    --log-type INFO_LOGS
```

```bash title="Output"
{
    "deliverySource": {
        "name": "large-orders-logs",
        "arn": "arn:aws:logs:us-east-1:000000000000:delivery-source:large-orders-logs",
        "resourceArns": [
            "arn:aws:events:us-east-1:000000000000:subscriber/large-orders/avf41lgwcg1a0yphcqquygj5p"
        ],
        "service": "events",
        "logType": "INFO_LOGS"
    }
}
```

Create a delivery destination for the log group, and connect the two with a delivery:

```bash
lstk aws logs put-delivery-destination \
    --name large-orders-log-group \
    --delivery-destination-configuration destinationResourceArn=arn:aws:logs:us-east-1:000000000000:log-group:/aws/vendedlogs/large-orders
lstk aws logs create-delivery \
    --delivery-source-name large-orders-logs \
    --delivery-destination-arn arn:aws:logs:us-east-1:000000000000:delivery-destination:large-orders-log-group
```

When an event is delivered, the log group receives a `SUBSCRIBER_MATCHED` record and an `EVENT_DELIVERY_ATTEMPT` record.
The following command shows the main fields of the delivery attempt:

```bash
lstk aws logs filter-log-events \
    --log-group-name /aws/vendedlogs/large-orders \
    --filter-pattern '{ $.message_type = "EVENT_DELIVERY_ATTEMPT" }' \
    --query 'events[0].message' \
    --output text | jq '{message_type, event_id, details: (.details | {outcome, attempt_count, target_arn})}'
```

```bash title="Output"
{
  "message_type": "EVENT_DELIVERY_ATTEMPT",
  "event_id": "9e9e2070-7b43-4f24-8ab8-5c765255f0af",
  "details": {
    "outcome": "SUCCESS",
    "attempt_count": 1,
    "target_arn": "arn:aws:sqs:us-east-1:000000000000:orders-queue"
  }
}
```

Failed attempts, transformation failures, and dead-letter queue writes are logged as well, with their error code and message.

## Access control and sharing

### IAM enforcement

LocalStack enforces the bus resource policies, the delivery role, and identity policies when you start it with [IAM enforcement](/aws/developer-tools/security-testing/iam-policy-enforcement/) (`ENFORCE_IAM=1`).
Without IAM enforcement, any account can publish to and subscribe to any bus, while operations reserved for the bus owner, such as `UpdateEventBus`, still fail from other accounts.

### Sharing a bus with AWS RAM

You can share a bus with other accounts through [AWS RAM](/aws/services/ram/), with one of the four [AWS managed permissions](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-custom-bus-sharing.html) for event buses.
Share the bus with the account `111111111111`:

```bash
lstk aws ram create-resource-share \
    --name orders-bus-share \
    --resource-arns arn:aws:events:us-east-1:000000000000:event-busv2/orders-bus/umsn1mzdebj8ynyo3i9hphbdq \
    --principals 111111111111 \
    --permission-arns arn:aws:ram::aws:permission/AWSRAMEventBridgeEventBusV2SubscribeOnly
```

```bash title="Output"
{
    "resourceShare": {
        "resourceShareArn": "arn:aws:ram:us-east-1:000000000000:resource-share/ce58f3ad-7e97-4359-9180-40549d91754b",
        "name": "orders-bus-share",
        "owningAccountId": "000000000000",
        "allowExternalPrincipals": true,
        "status": "ACTIVE",
        "tags": [],
        "creationTime": "2026-11-04T20:54:45.694475+01:00",
        "lastUpdatedTime": "2026-11-04T20:54:45.694476+01:00",
        "resourceShareConfiguration": {
            "retainSharingOnAccountLeaveOrganization": false
        }
    }
}
```

The shared bus now appears in the consumer account's list of buses:

```bash
lstk aws --account 111111111111 eventsv2 list-event-buses
```

```bash title="Output"
{
    "EventBuses": [
        {
            "Name": "orders-bus",
            "EventBusArn": "arn:aws:events:us-east-1:000000000000:event-busv2/orders-bus/umsn1mzdebj8ynyo3i9hphbdq",
            "EventBusAccountId": "000000000000"
        }
    ]
}
```

The consumer account creates subscribers on the shared bus in its own account, with its own delivery role and target.
The following command assumes that the account `111111111111` has a `shipping-queue` queue and a `shipping-delivery-role` role, created as in the getting started guide:

```bash
lstk aws --account 111111111111 eventsv2 create-subscriber \
    --name shipping \
    --event-bus-arn arn:aws:events:us-east-1:000000000000:event-busv2/orders-bus/umsn1mzdebj8ynyo3i9hphbdq \
    --invoke-configuration TargetArn=arn:aws:sqs:us-east-1:111111111111:shipping-queue,RoleArn=arn:aws:iam::111111111111:role/shipping-delivery-role
```

```bash title="Output"
{
    "SubscriberArn": "arn:aws:events:us-east-1:111111111111:subscriber/shipping/0tur41je37r6hoy0ky72pzlvp",
    "Name": "shipping",
    "EventBusArn": "arn:aws:events:us-east-1:000000000000:event-busv2/orders-bus/umsn1mzdebj8ynyo3i9hphbdq",
    "Type": "UNORDERED",
    "StartingPosition": "LATEST",
    "State": "RUNNING",
    "CreationTime": "2026-11-04T20:54:57.335582+01:00"
}
```

The events that the owner publishes now also reach the consumer's queue.

## Persistence

With [persistence](/aws/developer-tools/snapshots/persistence/) or a snapshot, LocalStack keeps the event buses with their policies and tags, the subscribers, the event sources, the retained events, and each subscriber's position.
After a restart, subscribers continue where they left off: events that were waiting for delivery or a retry are delivered again, with a fresh retry budget.
The deduplication window is not kept, so an event published again within 5 minutes after a restart is not treated as a duplicate.

## Current Limitations

- LocalStack does not support partner event sources, in the Custom Event Bus or in [EventBridge](/aws/services/events/). Creating an event source with a `PartnerEventsConfiguration` fails.
- `PutRawEvents` decodes Avro events from a Glue Schema Registry only. Protobuf events and Confluent schema registries are rejected.
- With IAM enforcement, LocalStack does not check whether the caller of `PutRawEvents` may read the schema with `glue:GetSchemaVersion`. A caller without that permission can still publish Avro events.
- LocalStack does not emit the Custom Event Bus CloudWatch metrics.
- Subscriber logs are only delivered to CloudWatch Logs log groups in the same account and region. S3, Firehose, and cross-account delivery destinations receive no logs.
- When a bus is shared through AWS RAM, only account principals get access. Organization and organizational unit principals don't, and the `AWS_RAM` policy has no `aws:PrincipalOrgID` condition.
- LocalStack does not check whether the caller may use the KMS key of an encrypted bus, and it accepts events for a bus whose key is disabled.
- Changes take effect immediately. On AWS, new subscribers, state and filter changes, and shares can take a few seconds to apply, and events published while a point-in-time subscriber starts may be marked as `REPLAY`. Tests that pass on LocalStack may need waits on AWS.
- LocalStack enforces the quota of 5 event buses per account and region, but not the other [Custom Event Bus quotas](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-quota.html#eb-custom-bus-quotas), such as the number of concurrent replays per bus or one subscriber creation or deletion at a time per bus.

## API Coverage


### eventbridgev2 API coverage

Source service: `eventbridgev2`. 24 of 25 tracked operations are implemented.

Service documentation: /aws/services/eventbridgev2/
License availability: available starting with the Ultimate plan. See /aws/licensing/ for current plan details.

| Operation | Status |
| --- | --- |
| CreateEventBus | Implemented |
| CreateEventSource | Implemented |
| CreateSubscriber | Implemented |
| DeleteEventBus | Implemented |
| DeleteEventSource | Implemented |
| DeleteResourcePolicy | Implemented |
| DeleteSubscriber | Implemented |
| DescribeEventBus | Implemented |
| DescribeEventSource | Implemented |
| DescribeSubscriber | Implemented |
| GetResourcePolicy | Implemented |
| ListEventBuses | Implemented |
| ListEventSources | Implemented |
| ListResourcePolicies | Implemented |
| ListSubscribers | Implemented |
| ListTagsForResource | Implemented |
| PutEvents | Implemented |
| PutRawEvents | Implemented |
| PutResourcePolicy | Implemented |
| RevokeResource | Not implemented |
| TagResource | Implemented |
| UntagResource | Implemented |
| UpdateEventBus | Implemented |
| UpdateEventSource | Implemented |
| UpdateSubscriber | Implemented |
