Class Rule
- All Implemented Interfaces:
IResource,IRule,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct,software.constructs.IDependable
Example:
import software.amazon.awscdk.services.lambda.*;
Function fn = Function.Builder.create(this, "MyFunc")
.runtime(Runtime.NODEJS_LATEST)
.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.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.services.events.IRule
IRule.Jsii$Default, IRule.Jsii$Proxy -
Field Summary
Fields -
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.Methods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResourceMethods inherited from class software.constructs.Construct
getNode, isConstruct, 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.constructs.IConstruct
getNodeMethods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStackMethods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Field Details
-
PROPERTY_INJECTION_ID
Uniquely identifies this class.
-
-
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::invalid input: '<'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.
-
validateRule
-
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
-