interface RuleProps
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.Events.RuleProps |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsevents#RuleProps |
Java | software.amazon.awscdk.services.events.RuleProps |
Python | aws_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_LATEST,
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
Name | Type | Description |
---|---|---|
cross | Construct | The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region). |
description? | string | A description of the rule's purpose. |
enabled? | boolean | Indicates whether the rule is enabled. |
event | IEvent | The event bus to associate with this rule. |
event | Event | Additional restrictions for the event to route to the specified target. |
rule | string | A name for the rule. |
schedule? | Schedule | The schedule or rate (frequency) that determines when EventBridge runs the rule. |
targets? | IRule [] | 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:
IEvent
(optional, default: The default event bus.)
The event bus to associate with this rule.
eventPattern?
Type:
Event
(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.
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:
IRule
[]
(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])
.