EventBus

class aws_cdk.aws_events.EventBus(scope, id, *, dead_letter_queue=None, description=None, event_bus_name=None, event_source_name=None, kms_key=None)

Bases: Resource

Define an EventBridge EventBus.

Resource:

AWS::Events::EventBus

ExampleMetadata:

infused

Example:

bus = events.EventBus(self, "bus",
    event_bus_name="MyCustomEventBus",
    description="MyCustomEventBus"
)

bus.archive("MyArchive",
    archive_name="MyCustomEventBusArchive",
    description="MyCustomerEventBus Archive",
    event_pattern=events.EventPattern(
        account=[Stack.of(self).account]
    ),
    retention=Duration.days(365)
)
Parameters:
  • scope (Construct)

  • id (str)

  • dead_letter_queue (Optional[IQueue]) – Dead-letter queue for the event bus. Default: - no dead-letter queue

  • description (Optional[str]) – The event bus description. The description can be up to 512 characters long. Default: - no description

  • event_bus_name (Optional[str]) – The name of the event bus you are creating Note: If ‘eventSourceName’ is passed in, you cannot set this. Default: - automatically generated name

  • event_source_name (Optional[str]) – The partner event source to associate with this event bus resource Note: If ‘eventBusName’ is passed in, you cannot set this. Default: - no partner event source

  • kms_key (Optional[IKey]) – The customer managed key that encrypt events on this event bus. Default: - Use an AWS managed key

Methods

add_to_resource_policy(statement)

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

Parameters:

statement (PolicyStatement)

Return type:

AddToResourcePolicyResult

apply_removal_policy(policy)

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).

Parameters:

policy (RemovalPolicy)

Return type:

None

archive(id, *, event_pattern, archive_name=None, description=None, retention=None)

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.

Parameters:
  • id (str)

  • event_pattern (Union[EventPattern, Dict[str, Any]]) – An event pattern to use to filter events sent to the archive.

  • archive_name (Optional[str]) – The name of the archive. Default: - Automatically generated

  • description (Optional[str]) – A description for the archive. Default: - none

  • retention (Optional[Duration]) – The number of days to retain events for. Default value is 0. If set to 0, events are retained indefinitely. Default: - Infinite

Return type:

Archive

grant_put_events_to(grantee)

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

Parameters:

grantee (IGrantable)

Return type:

Grant

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

env

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.

event_bus_arn

aws:events:us-east-2:123456789012:event-bus/aws.partner/PartnerName/acct1/repo1.

Type:

The ARN of the event bus, such as

Type:

arn

event_bus_name

The physical ID of this event bus resource.

event_bus_policy

The policy for the event bus in JSON form.

event_source_name

The name of the partner event source.

node

The tree node.

stack

The stack in which this resource is defined.

Static Methods

classmethod from_event_bus_arn(scope, id, event_bus_arn)

Import an existing event bus resource.

Parameters:
  • scope (Construct) – Parent construct.

  • id (str) – Construct ID.

  • event_bus_arn (str) – ARN of imported event bus.

Return type:

IEventBus

classmethod from_event_bus_attributes(scope, id, *, event_bus_arn, event_bus_name, event_bus_policy, event_source_name=None)

Import an existing event bus resource.

Parameters:
  • scope (Construct) – Parent construct.

  • id (str) – Construct ID.

  • event_bus_arn (str) – The ARN of this event bus resource.

  • event_bus_name (str) – The physical ID of this event bus resource.

  • event_bus_policy (str) – The JSON policy of this event bus resource.

  • event_source_name (Optional[str]) – The partner event source to associate with this event bus resource. Default: - no partner event source

Return type:

IEventBus

classmethod from_event_bus_name(scope, id, event_bus_name)

Import an existing event bus resource.

Parameters:
  • scope (Construct) – Parent construct.

  • id (str) – Construct ID.

  • event_bus_name (str) – Name of imported event bus.

Return type:

IEventBus

classmethod grant_all_put_events(grantee)

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

Parameters:

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

Return type:

Grant

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Construct.

classmethod is_owned_resource(construct)

Returns true if the construct was created by CDK, and false otherwise.

Parameters:

construct (IConstruct)

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct)

Return type:

bool