# Rule

Defines an EventBridge Rule in this stack.

Extends: Construct › Resource › Rule
Implements: IResource, IRule, IEnvironmentAware, IRuleRef, IConstruct, IDependable

- CloudFormation: [`AWS::Events::Rule`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-events-rule.html)
- L1 type: [`CfnRule`](/cdk/api/v2/docs/aws-cdk-lib.aws_events.CfnRule.html)
- Source: [`aws-events/lib/rule.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-events/lib/rule.ts#L79)
- Type last changed: v2.235.0 · 15 Jan 2026

## Example

```ts
import * as redshiftserverless from 'aws-cdk-lib/aws-redshiftserverless'

declare const workgroup: redshiftserverless.CfnWorkgroup;

const rule = new events.Rule(this, 'Rule', {
  schedule: events.Schedule.rate(cdk.Duration.hours(1)),
});

const dlq = new sqs.Queue(this, 'DeadLetterQueue');

rule.addTarget(new targets.RedshiftQuery(workgroup.attrWorkgroupWorkgroupArn, {
  database: 'dev',
  deadLetterQueue: dlq,
  sql: ['SELECT * FROM foo','SELECT * FROM baz'],
}));
```

## Initializer

```ts
new Rule(scope: Construct, id: string, props?: RuleProps)
```

## Construct Props

- `crossStackScope`: [Construct](/cdk/api/v2/docs/constructs.Construct.html) — The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region).

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

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

- `description`: string — A description of the rule's purpose.

  **Default:** No description

- `enabled`: boolean = true — Indicates whether the rule is enabled.

- `eventBus`: [IEventBusRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_events.IEventBusRef.html) — The event bus to associate with this rule.

  **Default:** The default event bus.

- `eventPattern`: [EventPattern](/cdk/api/v2/docs/aws-cdk-lib.aws_events.EventPattern.html) — Additional restrictions for the event to route to the specified target.

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

  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.

- `role`: [IRoleRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_iam.IRoleRef.html) — The role that is used for target invocation.

  **Default:** No role associated

  Must be assumable by principal `events.amazonaws.com`.

- `ruleName`: string — A name for the rule.

  **Default:** AWS CloudFormation generates a unique physical ID.

- `schedule`: [Schedule](/cdk/api/v2/docs/aws-cdk-lib.aws_events.Schedule.html) = None. — 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.

- `targets`: [IRuleTarget](/cdk/api/v2/docs/aws-cdk-lib.aws_events.IRuleTarget.html)[] — Targets to invoke when this rule matches an event.

  **Default:** No targets.

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

## Properties

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `ruleArn`: string — The value of the event rule Amazon Resource Name (ARN), such as arn:aws:events:us-east-2:123456789012:rule/example.

- `ruleName`: string — The name event rule.

- `ruleRef`: [RuleReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_events.RuleReference.html) — A reference to a Rule resource.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

## Methods

- `addEventPattern(eventPattern?: EventPattern): void` — 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" ]
       }
     }

- `addTarget(target?: IRuleTarget): void` — Adds a target to the rule. The abstract class RuleTarget can be extended to define new targets.

  No-op if target is undefined.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — 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`).

- `fromEventRuleArn(scope: Construct, id: string, eventRuleArn: string): IRule` (static) — Import an existing EventBridge Rule provided an ARN.

  **Parameters**

  - `scope` — The parent creating construct (usually `this`).
  - `id` — The construct's name.
  - `eventRuleArn` — Event Rule ARN (i.e. arn:aws:events:<region>:<account-id>:rule/MyScheduledRule).

- `isConstruct(x: any): boolean` (static) — 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 object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
