aws-cdk-lib.aws_events.EventBus

class EventBus (construct)

LanguageType name
.NETAmazon.CDK.AWS.Events.EventBus
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsevents#EventBus
Javasoftware.amazon.awscdk.services.events.EventBus
Pythonaws_cdk.aws_events.EventBus
TypeScript (source)aws-cdk-lib » aws_events » EventBus

Implements IConstruct, IDependable, IResource, IEventBus

Define an EventBridge EventBus.

Example

const bus = new events.EventBus(this, 'bus', {
  eventBusName: 'MyCustomEventBus'
});

bus.archive('MyArchive', {
  archiveName: 'MyCustomEventBusArchive',
  description: 'MyCustomerEventBus Archive',
  eventPattern: {
    account: [Stack.of(this).account],
  },
  retention: Duration.days(365),
});

Initializer

new EventBus(scope: Construct, id: string, props?: EventBusProps)

Parameters

  • scope Construct
  • id string
  • props EventBusProps

Construct Props

NameTypeDescription
eventBusName?stringThe name of the event bus you are creating Note: If 'eventSourceName' is passed in, you cannot set this.
eventSourceName?stringThe partner event source to associate with this event bus resource Note: If 'eventBusName' is passed in, you cannot set this.

eventBusName?

Type: string (optional, default: automatically generated name)

The name of the event bus you are creating Note: If 'eventSourceName' is passed in, you cannot set this.


eventSourceName?

Type: string (optional, default: no partner event source)

The partner event source to associate with this event bus resource Note: If 'eventBusName' is passed in, you cannot set this.

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
eventBusArnstringThe ARN of the event bus, such as: arn:aws:events:us-east-2:123456789012:event-bus/aws.partner/PartnerName/acct1/repo1.
eventBusNamestringThe physical ID of this event bus resource.
eventBusPolicystringThe policy for the event bus in JSON form.
nodeNodeThe tree node.
stackStackThe stack in which this resource is defined.
eventSourceName?stringThe name of the partner event source.

env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


eventBusArn

Type: string

The ARN of the event bus, such as: arn:aws:events:us-east-2:123456789012:event-bus/aws.partner/PartnerName/acct1/repo1.


eventBusName

Type: string

The physical ID of this event bus resource.


eventBusPolicy

Type: string

The policy for the event bus in JSON form.


node

Type: Node

The tree node.


stack

Type: Stack

The stack in which this resource is defined.


eventSourceName?

Type: string (optional)

The name of the partner event source.

Methods

NameDescription
addToResourcePolicy(statement)Adds a statement to the IAM resource policy associated with this event bus.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
archive(id, props)Create an EventBridge archive to send events to.
grantPutEventsTo(grantee)Grants an IAM Principal to send custom events to the eventBus so that they can be matched to rules.
toString()Returns a string representation of this construct.
static fromEventBusArn(scope, id, eventBusArn)Import an existing event bus resource.
static fromEventBusAttributes(scope, id, attrs)Import an existing event bus resource.
static fromEventBusName(scope, id, eventBusName)Import an existing event bus resource.
static grantAllPutEvents(grantee)Permits an IAM Principal to send custom events to EventBridge so that they can be matched to rules.

addToResourcePolicy(statement)

public addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult

Parameters

  • statement PolicyStatement

Returns

  • AddToResourcePolicyResult

Adds a statement to the IAM resource policy associated with this event bus.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


archive(id, props)

public archive(id: string, props: BaseArchiveProps): Archive

Parameters

  • id string
  • props BaseArchiveProps

Returns

  • Archive

Create an EventBridge archive to send events to.

When you create an archive, incoming events might not immediately start being sent to the archive. Allow a short period of time for changes to take effect.


grantPutEventsTo(grantee)

public grantPutEventsTo(grantee: IGrantable): Grant

Parameters

  • grantee IGrantable

Returns

  • Grant

Grants an IAM Principal to send custom events to the eventBus so that they can be matched to rules.


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromEventBusArn(scope, id, eventBusArn)

public static fromEventBusArn(scope: Construct, id: string, eventBusArn: string): IEventBus

Parameters

  • scope Construct — Parent construct.
  • id string — Construct ID.
  • eventBusArn string — ARN of imported event bus.

Returns

  • IEventBus

Import an existing event bus resource.


static fromEventBusAttributes(scope, id, attrs)

public static fromEventBusAttributes(scope: Construct, id: string, attrs: EventBusAttributes): IEventBus

Parameters

  • scope Construct — Parent construct.
  • id string — Construct ID.
  • attrs EventBusAttributes — Imported event bus properties.

Returns

  • IEventBus

Import an existing event bus resource.


static fromEventBusName(scope, id, eventBusName)

public static fromEventBusName(scope: Construct, id: string, eventBusName: string): IEventBus

Parameters

  • scope Construct — Parent construct.
  • id string — Construct ID.
  • eventBusName string — Name of imported event bus.

Returns

  • IEventBus

Import an existing event bus resource.


static grantAllPutEvents(grantee)

public static grantAllPutEvents(grantee: IGrantable): Grant

Parameters

  • grantee IGrantable — The principal (no-op if undefined).

Returns

  • Grant

Permits an IAM Principal to send custom events to EventBridge so that they can be matched to rules.