java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
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());
 
  • 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.

    • validate

      @Stability(Stable) @NotNull protected List<String> 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.

      Overrides:
      validate in class Construct
      Returns:
      An array of validation error messages, or an empty array if the construct is valid.
    • 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