Rule

class aws_cdk.aws_events.Rule(scope, id, *, description=None, enabled=None, event_bus=None, event_pattern=None, rule_name=None, schedule=None, targets=None)

Bases: aws_cdk.core.Resource

Defines a CloudWatch Event Rule in this stack.

resource: :resource:: AWS::Events::Rule

__init__(scope, id, *, description=None, enabled=None, event_bus=None, event_pattern=None, rule_name=None, schedule=None, targets=None)
Parameters
  • scope (Construct) –

  • id (str) –

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

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

  • event_pattern (Optional[EventPattern]) – Describes which events CloudWatch Events routes to the specified target. These routed events are matched events. For more information, see Events and Event Patterns in the Amazon CloudWatch User Guide. Default: - None.

  • rule_name (Optional[str]) – A name for the rule. Default: - AWS CloudFormation generates a unique physical ID and uses that ID for the rule name. For more information, see Name Type.

  • schedule (Optional[Schedule]) – The schedule or rate (frequency) that determines when CloudWatch Events runs the rule. For more information, see Schedule Expression Syntax for Rules in the Amazon CloudWatch User Guide. Default: - None.

  • targets (Optional[List[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.

Return type

None

Methods

add_event_pattern(*, account=None, detail=None, detail_type=None, id=None, region=None, resources=None, source=None, time=None, version=None)

Adds an event pattern filter to this rule.

If a pattern was already specified, these values are merged into the existing pattern.

For example, if the rule already contains the pattern:

{
  "resources": [ "r1" ],
  "detail": {
    "hello": [ 1 ]
  }
}

And addEventPattern is called with the pattern:

{
  "resources": [ "r2" ],
  "detail": {
    "foo": [ "bar" ]
  }
}

The resulting event pattern will be:

{
  "resources": [ "r1", "r2" ],
  "detail": {
    "hello": [ 1 ],
    "foo": [ "bar" ]
  }
}
Parameters
  • account (Optional[List[str]]) – The 12-digit number identifying an AWS account. Default: - No filtering on account

  • detail (Optional[Mapping[str, Any]]) – A JSON object, whose content is at the discretion of the service originating the event. Default: - No filtering on detail

  • detail_type (Optional[List[str]]) – Identifies, in combination with the source field, the fields and values that appear in the detail field. Represents the “detail-type” event field. Default: - No filtering on detail type

  • id (Optional[List[str]]) – A unique value is generated for every event. This can be helpful in tracing events as they move through rules to targets, and are processed. Default: - No filtering on id

  • region (Optional[List[str]]) – Identifies the AWS region where the event originated. Default: - No filtering on region

  • resources (Optional[List[str]]) – This JSON array contains ARNs that identify resources that are involved in the event. Inclusion of these ARNs is at the discretion of the service. For example, Amazon EC2 instance state-changes include Amazon EC2 instance ARNs, Auto Scaling events include ARNs for both instances and Auto Scaling groups, but API calls with AWS CloudTrail do not include resource ARNs. Default: - No filtering on resource

  • source (Optional[List[str]]) – Identifies the service that sourced the event. All events sourced from within AWS begin with “aws.” Customer-generated events can have any value here, as long as it doesn’t begin with “aws.” We recommend the use of Java package-name style reverse domain-name strings. To find the correct value for source for an AWS service, see the table in AWS Service Namespaces. For example, the source value for Amazon CloudFront is aws.cloudfront. Default: - No filtering on source

  • time (Optional[List[str]]) – The event timestamp, which can be specified by the service originating the event. If the event spans a time interval, the service might choose to report the start time, so this value can be noticeably before the time the event is actually received. Default: - No filtering on time

  • version (Optional[List[str]]) – By default, this is set to 0 (zero) in all events. Default: - No filtering on version

Return type

None

add_target(target=None)

Adds a target to the rule. The abstract class RuleTarget can be extended to define new targets.

No-op if target is undefined.

Parameters

target (Optional[IRuleTarget]) –

Return type

None

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

node

The construct tree node associated with this construct.

Return type

ConstructNode

rule_arn

events:us-east-2:123456789012:rule/example.

Type

The value of the event rule Amazon Resource Name (ARN), such as arn

Type

aws

Return type

str

rule_name

The name event rule.

Return type

str

stack

The stack in which this resource is defined.

Return type

Stack

Static Methods

classmethod from_event_rule_arn(scope, id, event_rule_arn)
Parameters
  • scope (Construct) –

  • id (str) –

  • event_rule_arn (str) –

Return type

IRule

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters

x (Any) –

Return type

bool