Interface EventPattern

All Superinterfaces:
software.amazon.jsii.JsiiSerializable
All Known Implementing Classes:
EventPattern.Jsii$Proxy

@Generated(value="jsii-pacmak/1.103.1 (build bef2dea)", date="2024-10-04T00:39:32.599Z") @Stability(Stable) public interface EventPattern extends software.amazon.jsii.JsiiSerializable
Events in Amazon CloudWatch Events are represented as JSON objects. For more information about JSON objects, see RFC 7159.

Important: this class can only be used with a Rule class. In particular, do not use it with CfnRule class: your pattern will not be rendered correctly. In a CfnRule class, write the pattern as you normally would when directly writing CloudFormation.

Rules use event patterns to select events and route them to targets. A pattern either matches an event or it doesn't. Event patterns are represented as JSON objects with a structure that is similar to that of events.

It is important to remember the following about event pattern matching:

  • For a pattern to match an event, the event must contain all the field names listed in the pattern. The field names must appear in the event with the same nesting structure.
  • Other fields of the event not mentioned in the pattern are ignored; effectively, there is a "*": "*" wildcard for fields not mentioned.
  • The matching is exact (character-by-character), without case-folding or any other string normalization.
  • The values being matched follow JSON rules: Strings enclosed in quotes, numbers, and the unquoted keywords true, false, and null.
  • Number matching is at the string representation level. For example, 300, 300.0, and 3.0e2 are not considered equal.

For custom events, some optional properties are required. For more information, see Minimum information needed for a valid custom event.

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());
 

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final class 
    A builder for EventPattern
    static final class 
    An implementation for EventPattern
  • Method Summary

    Modifier and Type
    Method
    Description
     
    default List<String>
    The 12-digit number identifying an AWS account.
    default Map<String,Object>
    A JSON object, whose content is at the discretion of the service originating the event.
    default List<String>
    Identifies, in combination with the source field, the fields and values that appear in the detail field.
    default List<String>
    A unique value is generated for every event.
    default List<String>
    Identifies the AWS region where the event originated.
    default List<String>
    This JSON array contains ARNs that identify resources that are involved in the event.
    default List<String>
    Identifies the service that sourced the event.
    default List<String>
    The event timestamp, which can be specified by the service originating the event.
    default List<String>
    By default, this is set to 0 (zero) in all events.

    Methods inherited from interface software.amazon.jsii.JsiiSerializable

    $jsii$toJson
  • Method Details

    • getAccount

      @Stability(Stable) @Nullable default List<String> getAccount()
      The 12-digit number identifying an AWS account.

      Default: - No filtering on account

    • getDetail

      @Stability(Stable) @Nullable default Map<String,Object> getDetail()
      A JSON object, whose content is at the discretion of the service originating the event.

      Default: - No filtering on detail

    • getDetailType

      @Stability(Stable) @Nullable default List<String> getDetailType()
      Identifies, in combination with the source field, the fields and values that appear in the detail field.

      Represents the "detail-type" event field.

      Default: - No filtering on detail type

    • getId

      @Stability(Stable) @Nullable default List<String> getId()
      A unique value is generated for every event.

      This can be helpful in tracing events as they move through rules to targets, and are processed.

      Default: - No filtering on id

    • getRegion

      @Stability(Stable) @Nullable default List<String> getRegion()
      Identifies the AWS region where the event originated.

      Default: - No filtering on region

    • getResources

      @Stability(Stable) @Nullable default List<String> getResources()
      This JSON array contains ARNs that identify resources that are involved in the event.

      Inclusion of these ARNs is at the discretion of the service.

      For example, Amazon EC2 instance state-changes include Amazon EC2 instance ARNs, Auto Scaling events include ARNs for both instances and Auto Scaling groups, but API calls with AWS CloudTrail do not include resource ARNs.

      Default: - No filtering on resource

    • getSource

      @Stability(Stable) @Nullable default List<String> getSource()
      Identifies the service that sourced the event.

      All events sourced from within AWS begin with "aws." Customer-generated events can have any value here, as long as it doesn't begin with "aws." We recommend the use of Java package-name style reverse domain-name strings.

      To find the correct value for source for an AWS service, see the table in AWS Service Namespaces. For example, the source value for Amazon CloudFront is aws.cloudfront.

      Default: - No filtering on source

      See Also:
    • getTime

      @Stability(Stable) @Nullable default List<String> getTime()
      The event timestamp, which can be specified by the service originating the event.

      If the event spans a time interval, the service might choose to report the start time, so this value can be noticeably before the time the event is actually received.

      Default: - No filtering on time

    • getVersion

      @Stability(Stable) @Nullable default List<String> getVersion()
      By default, this is set to 0 (zero) in all events.

      Default: - No filtering on version

    • builder

      @Stability(Stable) static EventPattern.Builder builder()
      Returns:
      a EventPattern.Builder of EventPattern