aws-cdk-lib.aws_events.RuleProps

interface RuleProps

LanguageType name
.NETAmazon.CDK.AWS.Events.RuleProps
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsevents#RuleProps
Javasoftware.amazon.awscdk.services.events.RuleProps
Pythonaws_cdk.aws_events.RuleProps
TypeScript (source)aws-cdk-lib » aws_events » RuleProps

Properties for defining an EventBridge Rule.

Example

import * as lambda from 'aws-cdk-lib/aws-lambda';

const fn = new lambda.Function(this, 'MyFunc', {
  runtime: lambda.Runtime.NODEJS_14_X,
  handler: 'index.handler',
  code: lambda.Code.fromInline(`exports.handler = handler.toString()`),
});

const rule = new events.Rule(this, 'rule', {
  eventPattern: {
    source: ["aws.ec2"],
  },
});

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

rule.addTarget(new targets.LambdaFunction(fn, {
  deadLetterQueue: queue, // Optional: add a dead letter queue
  maxEventAge: Duration.hours(2), // Optional: set the maxEventAge retry policy
  retryAttempts: 2, // Optional: set the max number of retry attempts
}));

Properties

NameTypeDescription
crossStackScope?ConstructThe scope to use if the source of the rule and its target are in different Stacks (but in the same account & region).
description?stringA description of the rule's purpose.
enabled?booleanIndicates whether the rule is enabled.
eventBus?IEventBusThe event bus to associate with this rule.
eventPattern?EventPatternAdditional restrictions for the event to route to the specified target.
ruleName?stringA name for the rule.
schedule?ScheduleThe schedule or rate (frequency) that determines when EventBridge runs the rule.
targets?IRuleTarget[]Targets to invoke when this rule matches an event.

crossStackScope?

Type: Construct (optional, default: none (the main scope will be used, even for cross-stack Events))

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.


description?

Type: string (optional, default: No description)

A description of the rule's purpose.


enabled?

Type: boolean (optional, default: true)

Indicates whether the rule is enabled.


eventBus?

Type: IEventBus (optional, default: The default event bus.)

The event bus to associate with this rule.


eventPattern?

Type: EventPattern (optional, default: No additional filtering based on an 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.

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


ruleName?

Type: string (optional, default: AWS CloudFormation generates a unique physical ID.)

A name for the rule.


schedule?

Type: Schedule (optional, default: 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.

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


targets?

Type: IRuleTarget[] (optional, default: No 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]).