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 classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.events.IRule
IRule.Jsii$Default, IRule.Jsii$Proxy
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an event pattern filter to this rule.void
addEventPattern
(EventPattern eventPattern) Adds an event pattern filter to this rule.void
Adds a target to the rule.void
addTarget
(IRuleTarget target) Adds a target to the rule.static IRule
fromEventRuleArn
(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, isResource
Methods inherited from class software.constructs.Construct
getNode, isConstruct, toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.constructs.IConstruct
getNode
Methods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStack
Methods 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::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
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" ] } }
- 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
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
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:
getRuleArn
in interfaceIRule
-
getRuleName
The name event rule.- Specified by:
getRuleName
in interfaceIRule
-