RuleProps

class aws_cdk.aws_events.RuleProps(*, cross_stack_scope=None, description=None, event_pattern=None, rule_name=None, enabled=None, event_bus=None, schedule=None, targets=None)

Bases: EventCommonOptions

Properties for defining an EventBridge Rule.

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.

  • enabled (Optional[bool]) – Indicates whether the rule is enabled. Default: true

  • event_bus (Optional[IEventBus]) – The event bus to associate with this rule. Default: - The default event bus.

  • schedule (Optional[Schedule]) – The schedule or rate (frequency) that determines when EventBridge runs the rule. You must specify this property, the eventPattern property, or both. For more information, see Schedule Expression Syntax for Rules in the Amazon EventBridge User Guide. Default: - None.

  • targets (Optional[Sequence[IRuleTarget]]) – Targets to invoke when this rule matches an event. Input will be the full matched event. If you wish to specify custom target input, use addTarget(target[, inputOptions]). Default: - No targets.

ExampleMetadata:

infused

Example:

import aws_cdk.aws_lambda as lambda_


fn = lambda_.Function(self, "MyFunc",
    runtime=lambda_.Runtime.NODEJS_LATEST,
    handler="index.handler",
    code=lambda_.Code.from_inline("exports.handler = handler.toString()")
)

rule = events.Rule(self, "rule",
    event_pattern=events.EventPattern(
        source=["aws.ec2"]
    )
)

queue = sqs.Queue(self, "Queue")

rule.add_target(targets.LambdaFunction(fn,
    dead_letter_queue=queue,  # Optional: add a dead letter queue
    max_event_age=Duration.hours(2),  # Optional: set the maxEventAge retry policy
    retry_attempts=2
))

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

enabled

Indicates whether the rule is enabled.

Default:

true

event_bus

The event bus to associate with this rule.

Default:
  • The default event bus.

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.

schedule

The schedule or rate (frequency) that determines when EventBridge runs the rule.

You must specify this property, the eventPattern property, or both.

For more information, see Schedule Expression Syntax for Rules in the Amazon EventBridge User Guide.

Default:
  • None.

See:

https://docs.aws.amazon.com/eventbridge/latest/userguide/scheduled-events.html

targets

Targets to invoke when this rule matches an event.

Input will be the full matched event. If you wish to specify custom target input, use addTarget(target[, inputOptions]).

Default:
  • No targets.