Show / Hide Table of Contents

Class EventPattern

Events in Amazon CloudWatch Events are represented as JSON objects. For more information about JSON objects, see RFC 7159.

Inheritance
object
EventPattern
Implements
IEventPattern
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: Amazon.CDK.AWS.Events
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class EventPattern : IEventPattern
Syntax (vb)
Public Class EventPattern Implements IEventPattern
Remarks

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 custom events, some optional properties are required. For more information, see Minimum information needed for a valid custom event.

    See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html

    ExampleMetadata: infused

    Examples
    using Amazon.CDK.AWS.Lambda;
    
    
                 var fn = new Function(this, "MyFunc", new FunctionProps {
                     Runtime = Runtime.NODEJS_LATEST,
                     Handler = "index.handler",
                     Code = Code.FromInline("exports.handler = handler.toString()")
                 });
    
                 var rule = new Rule(this, "rule", new RuleProps {
                     EventPattern = new EventPattern {
                         Source = new [] { "aws.ec2" }
                     }
                 });
    
                 var queue = new Queue(this, "Queue");
    
                 rule.AddTarget(new LambdaFunction(fn, new LambdaFunctionProps {
                     DeadLetterQueue = queue,  // Optional: add a dead letter queue
                     MaxEventAge = Duration.Hours(2),  // Optional: set the maxEventAge retry policy
                     RetryAttempts = 2
                 }));

    Synopsis

    Constructors

    EventPattern()

    Events in Amazon CloudWatch Events are represented as JSON objects. For more information about JSON objects, see RFC 7159.

    Properties

    Account

    The 12-digit number identifying an AWS account.

    Detail

    A JSON object, whose content is at the discretion of the service originating the event.

    DetailType

    Identifies, in combination with the source field, the fields and values that appear in the detail field.

    Id

    A unique value is generated for every event.

    Region

    Identifies the AWS region where the event originated.

    Resources

    This JSON array contains ARNs that identify resources that are involved in the event.

    Source

    Identifies the service that sourced the event.

    Time

    The event timestamp, which can be specified by the service originating the event.

    Version

    By default, this is set to 0 (zero) in all events.

    Constructors

    EventPattern()

    Events in Amazon CloudWatch Events are represented as JSON objects. For more information about JSON objects, see RFC 7159.

    public EventPattern()
    Remarks

    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 custom events, some optional properties are required. For more information, see Minimum information needed for a valid custom event.

      See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html

      ExampleMetadata: infused

      Examples
      using Amazon.CDK.AWS.Lambda;
      
      
                   var fn = new Function(this, "MyFunc", new FunctionProps {
                       Runtime = Runtime.NODEJS_LATEST,
                       Handler = "index.handler",
                       Code = Code.FromInline("exports.handler = handler.toString()")
                   });
      
                   var rule = new Rule(this, "rule", new RuleProps {
                       EventPattern = new EventPattern {
                           Source = new [] { "aws.ec2" }
                       }
                   });
      
                   var queue = new Queue(this, "Queue");
      
                   rule.AddTarget(new LambdaFunction(fn, new LambdaFunctionProps {
                       DeadLetterQueue = queue,  // Optional: add a dead letter queue
                       MaxEventAge = Duration.Hours(2),  // Optional: set the maxEventAge retry policy
                       RetryAttempts = 2
                   }));

      Properties

      Account

      The 12-digit number identifying an AWS account.

      public string[]? Account { get; set; }
      Property Value

      string[]

      Remarks

      Default: - No filtering on account

      Detail

      A JSON object, whose content is at the discretion of the service originating the event.

      public IDictionary<string, object>? Detail { get; set; }
      Property Value

      IDictionary<string, object>

      Remarks

      Default: - No filtering on detail

      DetailType

      Identifies, in combination with the source field, the fields and values that appear in the detail field.

      public string[]? DetailType { get; set; }
      Property Value

      string[]

      Remarks

      Represents the "detail-type" event field.

      Default: - No filtering on detail type

      Id

      A unique value is generated for every event.

      public string[]? Id { get; set; }
      Property Value

      string[]

      Remarks

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

      Default: - No filtering on id

      Region

      Identifies the AWS region where the event originated.

      public string[]? Region { get; set; }
      Property Value

      string[]

      Remarks

      Default: - No filtering on region

      Resources

      This JSON array contains ARNs that identify resources that are involved in the event.

      public string[]? Resources { get; set; }
      Property Value

      string[]

      Remarks

      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

      Source

      Identifies the service that sourced the event.

      public string[]? Source { get; set; }
      Property Value

      string[]

      Remarks

      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: http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-aws-service-namespaces

      Time

      The event timestamp, which can be specified by the service originating the event.

      public string[]? Time { get; set; }
      Property Value

      string[]

      Remarks

      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

      Version

      By default, this is set to 0 (zero) in all events.

      public string[]? Version { get; set; }
      Property Value

      string[]

      Remarks

      Default: - No filtering on version

      Implements

      IEventPattern
      Back to top Generated by DocFX