Class Rule
java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.core.Construct
software.amazon.awscdk.core.Resource
software.amazon.awscdk.services.events.Rule
- All Implemented Interfaces:
IConstruct,IDependable,IResource,IRule,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct
@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)",
date="2023-06-19T16:30:37.052Z")
@Stability(Stable)
public class Rule
extends Resource
implements IRule
Defines an EventBridge Rule in this stack.
Example:
import software.amazon.awscdk.services.lambda.*;
Function fn = Function.Builder.create(this, "MyFunc")
.runtime(Runtime.NODEJS_14_X)
.handler("index.handler")
.code(Code.fromInline("exports.handler = handler.toString()"))
.build();
Rule rule = Rule.Builder.create(this, "rule")
.eventPattern(EventPattern.builder()
.source(List.of("aws.ec2"))
.build())
.build();
Queue queue = new Queue(this, "Queue");
rule.addTarget(LambdaFunction.Builder.create(fn)
.deadLetterQueue(queue) // Optional: add a dead letter queue
.maxEventAge(Duration.hours(2)) // Optional: set the maxEventAge retry policy
.retryAttempts(2)
.build());
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationModeNested classes/interfaces inherited from interface software.amazon.awscdk.core.IConstruct
IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.core.IResource
IResource.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.services.events.IRule
IRule.Jsii$Default, IRule.Jsii$Proxy -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an event pattern filter to this rule.voidaddEventPattern(EventPattern eventPattern) Adds an event pattern filter to this rule.voidAdds a target to the rule.voidaddTarget(IRuleTarget target) Adds a target to the rule.static IRulefromEventRuleArn(software.constructs.Construct scope, String id, String eventRuleArn) Import an existing EventBridge Rule provided an ARN.The value of the event rule Amazon Resource Name (ARN), such as arn:aws:events:us-east-2:123456789012:rule/example.The name event rule.validate()Validate the current construct.Methods inherited from class software.amazon.awscdk.core.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isResourceMethods inherited from class software.amazon.awscdk.core.Construct
getNode, isConstruct, onPrepare, onSynthesize, onValidate, prepare, synthesizeMethods inherited from class software.constructs.Construct
toStringMethods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.amazon.awscdk.core.IConstruct
getNodeMethods inherited from interface software.amazon.awscdk.core.IResource
applyRemovalPolicy, getEnv, getStackMethods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
Rule
protected Rule(software.amazon.jsii.JsiiObjectRef objRef) -
Rule
protected Rule(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
Rule
@Stability(Stable) public Rule(@NotNull software.constructs.Construct scope, @NotNull String id, @Nullable RuleProps props) - Parameters:
scope- This parameter is required.id- This parameter is required.props-
-
Rule
- Parameters:
scope- This parameter is required.id- This parameter is required.
-
-
Method Details
-
fromEventRuleArn
@Stability(Stable) @NotNull public static IRule fromEventRuleArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String eventRuleArn) Import an existing EventBridge Rule provided an ARN.- Parameters:
scope- The parent creating construct (usuallythis). This parameter is required.id- The construct's name. This parameter is required.eventRuleArn- Event Rule ARN (i.e. arn:aws:events::<account-id>:rule/MyScheduledRule). This parameter is required.
-
addEventPattern
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
addEventPatternis called with the pattern:{ "resources": [ "r2" ], "detail": { "foo": [ "bar" ] } }The resulting event pattern will be:
{ "resources": [ "r1", "r2" ], "detail": { "hello": [ 1 ], "foo": [ "bar" ] } }- Parameters:
eventPattern-
-
addEventPattern
@Stability(Stable) public void addEventPattern()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
addEventPatternis called with the pattern:{ "resources": [ "r2" ], "detail": { "foo": [ "bar" ] } }The resulting event pattern will be:
{ "resources": [ "r1", "r2" ], "detail": { "hello": [ 1 ], "foo": [ "bar" ] } } -
addTarget
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-
-
addTarget
@Stability(Stable) public void addTarget()Adds a target to the rule. The abstract class RuleTarget can be extended to define new targets.No-op if target is undefined.
-
validate
Validate the current construct.This method can be implemented by derived constructs in order to perform validation logic. It is called on all constructs before synthesis.
-
getRuleArn
The value of the event rule Amazon Resource Name (ARN), such as arn:aws:events:us-east-2:123456789012:rule/example.- Specified by:
getRuleArnin interfaceIRule
-
getRuleName
The name event rule.- Specified by:
getRuleNamein interfaceIRule
-