java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.events.Rule
All Implemented Interfaces:
IResource, IRule, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.103.1 (build bef2dea)", date="2024-09-11T18:01:16.250Z") @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_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());
 
  • 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

      @Stability(Stable) public Rule(@NotNull software.constructs.Construct scope, @NotNull String id)
      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 (usually this). 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

      @Stability(Stable) public void addEventPattern(@Nullable EventPattern eventPattern)
      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

      @Stability(Stable) public void addTarget(@Nullable IRuleTarget target)
      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

      @Stability(Stable) @NotNull protected List<String> validateRule()
    • getRuleArn

      @Stability(Stable) @NotNull public String 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 interface IRule
    • getRuleName

      @Stability(Stable) @NotNull public String getRuleName()
      The name event rule.
      Specified by:
      getRuleName in interface IRule