Class EventRule


  • public class EventRule
    extends com.pulumi.resources.CustomResource
    Provides an EventBridge Rule resource. > **Note:** EventBridge was formerly known as CloudWatch Events. The functionality is identical. ## Example Usage
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.cloudwatch.EventRule;
     import com.pulumi.aws.cloudwatch.EventRuleArgs;
     import com.pulumi.aws.sns.Topic;
     import com.pulumi.aws.sns.TopicArgs;
     import com.pulumi.aws.cloudwatch.EventTarget;
     import com.pulumi.aws.cloudwatch.EventTargetArgs;
     import com.pulumi.aws.iam.IamFunctions;
     import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
     import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementArgs;
     import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementPrincipalArgs;
     import com.pulumi.aws.sns.TopicPolicy;
     import com.pulumi.aws.sns.TopicPolicyArgs;
     import static com.pulumi.codegen.internal.Serialization.*;
     import java.util.ArrayList;
     import java.util.Arrays;
     import java.util.Map;
     import java.io.File;
     import java.nio.file.Files;
     import java.nio.file.Paths;
     
     public class App {
         public static void main(String[] args) {
             Pulumi.run(App::stack);
         }
     
         public static void stack(Context ctx) {
             var console = new EventRule("console", EventRuleArgs.builder()
                 .name("capture-aws-sign-in")
                 .description("Capture each AWS Console Sign In")
                 .eventPattern(serializeJson(
                     jsonObject(
                         jsonProperty("detail-type", jsonArray("AWS Console Sign In via CloudTrail"))
                     )))
                 .build());
     
             var awsLogins = new Topic("awsLogins", TopicArgs.builder()
                 .name("aws-console-logins")
                 .build());
     
             var sns = new EventTarget("sns", EventTargetArgs.builder()
                 .rule(console.name())
                 .targetId("SendToSNS")
                 .arn(awsLogins.arn())
                 .build());
     
             final var snsTopicPolicy = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
                 .statements(GetPolicyDocumentStatementArgs.builder()
                     .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                         .type("Service")
                         .identifiers("events.amazonaws.com")
                         .build())
                     .effect("Allow")
                     .actions("SNS:Publish")
                     .resources(awsLogins.arn())
                     .build())
                 .build());
     
             var default_ = new TopicPolicy("default", TopicPolicyArgs.builder()
                 .arn(awsLogins.arn())
                 .policy(snsTopicPolicy.applyValue(_snsTopicPolicy -> _snsTopicPolicy.json()))
                 .build());
     
         }
     }
     
     
    ## Import ### Identity Schema #### Required * `name` (String) Name of the EventBridge rule. #### Optional * `accountId` (String) AWS Account where this resource is managed. * `region` (String) Region where this resource is managed. Using `pulumi import`, import EventBridge Rules using the `event_bus_name/rule_name` (if you omit `eventBusName`, the `default` event bus will be used). For example: ```sh $ pulumi import aws:cloudwatch/eventRule:EventRule example example-event-bus/capture-console-sign-in ```
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.pulumi.resources.CustomResource

        com.pulumi.resources.CustomResource.CustomResourceInternal
      • Nested classes/interfaces inherited from class com.pulumi.resources.Resource

        com.pulumi.resources.Resource.LazyField<T extends java.lang.Object>, com.pulumi.resources.Resource.LazyFields, com.pulumi.resources.Resource.ResourceInternal
    • Field Summary

      • Fields inherited from class com.pulumi.resources.Resource

        childResources, remote
    • Constructor Summary

      Constructors 
      Constructor Description
      EventRule​(java.lang.String name)  
      EventRule​(java.lang.String name, EventRuleArgs args)  
      EventRule​(java.lang.String name, EventRuleArgs args, com.pulumi.resources.CustomResourceOptions options)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.pulumi.core.Output<java.lang.String> arn()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> description()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> eventBusName()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> eventPattern()  
      com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> forceDestroy()  
      static EventRule get​(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, EventRuleState state, com.pulumi.resources.CustomResourceOptions options)
      Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
      com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> isEnabled()  
      com.pulumi.core.Output<java.lang.String> name()  
      com.pulumi.core.Output<java.lang.String> namePrefix()  
      com.pulumi.core.Output<java.lang.String> region()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> roleArn()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> scheduleExpression()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> state()  
      com.pulumi.core.Output<java.util.Optional<java.util.Map<java.lang.String,​java.lang.String>>> tags()  
      com.pulumi.core.Output<java.util.Map<java.lang.String,​java.lang.String>> tagsAll()  
      • Methods inherited from class com.pulumi.resources.CustomResource

        getId, id, idFuture
      • Methods inherited from class com.pulumi.resources.Resource

        getChildResources, getResourceName, getResourceType, getUrn, pulumiChildResources, pulumiResourceName, pulumiResourceType, urn
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EventRule

        public EventRule​(java.lang.String name)
        Parameters:
        name - The _unique_ name of the resulting resource.
      • EventRule

        public EventRule​(java.lang.String name,
                         @Nullable
                         EventRuleArgs args)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
      • EventRule

        public EventRule​(java.lang.String name,
                         @Nullable
                         EventRuleArgs args,
                         @Nullable
                         com.pulumi.resources.CustomResourceOptions options)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
        options - A bag of options that control this resource's behavior.
    • Method Detail

      • arn

        public com.pulumi.core.Output<java.lang.String> arn()
        Returns:
        ARN of the rule.
      • description

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> description()
        Returns:
        The description of the rule.
      • eventBusName

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> eventBusName()
        Returns:
        The name or ARN of the event bus to associate with this rule. If you omit this, the `default` event bus is used.
      • eventPattern

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> eventPattern()
        Returns:
        The event pattern described a JSON object. At least one of `scheduleExpression` or `eventPattern` is required. See full documentation of [Events and Event Patterns in EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html) for details. **Note**: The event pattern size is 2048 by default but it is adjustable up to 4096 characters by submitting a service quota increase request. See [Amazon EventBridge quotas](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-quota.html) for details.
      • forceDestroy

        public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> forceDestroy()
        Returns:
        Used to delete managed rules created by AWS. Defaults to `false`.
      • isEnabled

        public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> isEnabled()
        Returns:
        Whether the rule should be enabled. Defaults to `true`. Conflicts with `state`.
      • name

        public com.pulumi.core.Output<java.lang.String> name()
        Returns:
        The name of the rule. If omitted, this provider will assign a random, unique name. Conflicts with `namePrefix`.
      • namePrefix

        public com.pulumi.core.Output<java.lang.String> namePrefix()
        Returns:
        Creates a unique name beginning with the specified prefix. Conflicts with `name`. **Note**: Due to the length of the generated suffix, must be 38 characters or less.
      • region

        public com.pulumi.core.Output<java.lang.String> region()
        Returns:
        Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration.
      • roleArn

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> roleArn()
        Returns:
        ARN associated with the role that is used for target invocation.
      • scheduleExpression

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> scheduleExpression()
        Returns:
        The scheduling expression. For example, `cron(0 20 * * ? *)` or `rate(5 minutes)`. At least one of `scheduleExpression` or `eventPattern` is required. Can only be used on the default event bus. For more information, refer to the AWS documentation [Schedule Expressions for Rules](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html).
      • state

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> state()
        Returns:
        State of the rule. Valid values are `DISABLED`, `ENABLED`, and `ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS`. When state is `ENABLED`, the rule is enabled for all events except those delivered by CloudTrail. To also enable the rule for events delivered by CloudTrail, set `state` to `ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS`. Defaults to `ENABLED`. Conflicts with `isEnabled`.
      • tags

        public com.pulumi.core.Output<java.util.Optional<java.util.Map<java.lang.String,​java.lang.String>>> tags()
        Returns:
        A map of tags to assign to the resource. .If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level. **NOTE:** The rule state `ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS` cannot be used in conjunction with the `scheduleExpression` argument.
      • tagsAll

        public com.pulumi.core.Output<java.util.Map<java.lang.String,​java.lang.String>> tagsAll()
        Returns:
        A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
      • get

        public static EventRule get​(java.lang.String name,
                                    com.pulumi.core.Output<java.lang.String> id,
                                    @Nullable
                                    EventRuleState state,
                                    @Nullable
                                    com.pulumi.resources.CustomResourceOptions options)
        Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
        Parameters:
        name - The _unique_ name of the resulting resource.
        id - The _unique_ provider ID of the resource to lookup.
        state -
        options - Optional settings to control the behavior of the CustomResource.