OnEventOptions

class aws_cdk.aws_events.OnEventOptions(*, cross_stack_scope=None, description=None, event_pattern=None, rule_name=None, target=None)

Bases: EventCommonOptions

Standard set of options for onXxx event handlers on construct.

Parameters:
  • cross_stack_scope (Optional[Construct]) – The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region). This helps dealing with cycles that often arise in these situations. Default: - none (the main scope will be used, even for cross-stack Events)

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Union[EventPattern, Dict[str, Any], None]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

ExampleMetadata:

infused

Example:

import aws_cdk.aws_lambda as lambda_
from aws_cdk.aws_events_targets import LambdaFunction


repo = ecr.Repository(self, "Repo")
lambda_handler = lambda_.Function(self, "LambdaFunction",
    runtime=lambda_.Runtime.PYTHON_3_12,
    code=lambda_.Code.from_inline("# dummy func"),
    handler="index.handler"
)

repo.on_event("OnEventTargetLambda",
    target=LambdaFunction(lambda_handler)
)

Attributes

cross_stack_scope

The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region).

This helps dealing with cycles that often arise in these situations.

Default:
  • none (the main scope will be used, even for cross-stack Events)

description

A description of the rule’s purpose.

Default:
  • No description

event_pattern

Additional restrictions for the event to route to the specified target.

The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering.

Default:
  • No additional filtering based on an event pattern.

See:

https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html

rule_name

A name for the rule.

Default:

AWS CloudFormation generates a unique physical ID.

target

The target to register for the event.

Default:
  • No target is added to the rule. Use addTarget() to add a target.