Class EventPattern
Events in Amazon CloudWatch Events are represented as JSON objects. For more information about JSON objects, see RFC 7159.
Inheritance
Implements
Namespace: Amazon.CDK.AWS.Events
Assembly: Amazon.CDK.AWS.Events.dll
Syntax (csharp)
public class EventPattern : Object, IEventPattern
Syntax (vb)
Public Class EventPattern
Inherits Object
Implements IEventPattern
Remarks
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:
ExampleMetadata: infused
Examples
using Amazon.CDK.AWS.Lambda;
var fn = new Function(this, "MyFunc", new FunctionProps {
Runtime = Runtime.NODEJS_14_X,
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() |
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()
public EventPattern()
Properties
Account
The 12-digit number identifying an AWS account.
public string[] Account { get; set; }
Property Value
System.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
System.Collections.Generic.IDictionary<System.String, System.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
System.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
System.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
System.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
System.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
System.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
Time
The event timestamp, which can be specified by the service originating the event.
public string[] Time { get; set; }
Property Value
System.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
System.String[]
Remarks
Default: - No filtering on version