Show / Hide Table of Contents

Class Rule

Defines an EventBridge Rule in this stack.

Inheritance
object
Resource
Rule
Implements
IRule
IResource
IRuleRef
IConstruct
IDependable
IEnvironmentAware
Inherited Members
Resource.IsOwnedResource(IConstruct)
Resource.IsResource(IConstruct)
Resource.ApplyRemovalPolicy(RemovalPolicy)
Resource.GeneratePhysicalName()
Resource.GetResourceArnAttribute(string, IArnComponents)
Resource.GetResourceNameAttribute(string)
Resource.Env
Resource.PhysicalName
Resource.Stack
Namespace: Amazon.CDK.AWS.Events
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Rule : Resource, IRule, IResource, IRuleRef, IConstruct, IDependable, IEnvironmentAware
Syntax (vb)
Public Class Rule Inherits Resource Implements IRule, IResource, IRuleRef, IConstruct, IDependable, IEnvironmentAware
Remarks

Resource: AWS::Events::Rule

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

Rule(Construct, string, IRuleProps?)

Defines an EventBridge Rule in this stack.

Properties

PROPERTY_INJECTION_ID

Uniquely identifies this class.

RuleArn

The value of the event rule Amazon Resource Name (ARN), such as arn:aws:events:us-east-2:123456789012:rule/example.

RuleName

The name event rule.

RuleRef

A reference to a Rule resource.

Methods

AddEventPattern(IEventPattern?)

Adds an event pattern filter to this rule.

AddTarget(IRuleTarget?)

Adds a target to the rule. The abstract class RuleTarget can be extended to define new targets.

FromEventRuleArn(Construct, string, string)

Import an existing EventBridge Rule provided an ARN.

ValidateRule()

Defines an EventBridge Rule in this stack.

Constructors

Rule(Construct, string, IRuleProps?)

Defines an EventBridge Rule in this stack.

public Rule(Construct scope, string id, IRuleProps? props = null)
Parameters
scope Construct
id string
props IRuleProps
Remarks

Resource: AWS::Events::Rule

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

PROPERTY_INJECTION_ID

Uniquely identifies this class.

public static string PROPERTY_INJECTION_ID { get; }
Property Value

string

Remarks

Resource: AWS::Events::Rule

ExampleMetadata: infused

RuleArn

The value of the event rule Amazon Resource Name (ARN), such as arn:aws:events:us-east-2:123456789012:rule/example.

public virtual string RuleArn { get; }
Property Value

string

Remarks

Resource: AWS::Events::Rule

ExampleMetadata: infused

RuleName

The name event rule.

public virtual string RuleName { get; }
Property Value

string

Remarks

Resource: AWS::Events::Rule

ExampleMetadata: infused

RuleRef

A reference to a Rule resource.

public virtual IRuleReference RuleRef { get; }
Property Value

IRuleReference

Remarks

Resource: AWS::Events::Rule

ExampleMetadata: infused

Methods

AddEventPattern(IEventPattern?)

Adds an event pattern filter to this rule.

public virtual void AddEventPattern(IEventPattern? eventPattern = null)
Parameters
eventPattern IEventPattern
Remarks

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(IRuleTarget?)

Adds a target to the rule. The abstract class RuleTarget can be extended to define new targets.

public virtual void AddTarget(IRuleTarget? target = null)
Parameters
target IRuleTarget
Remarks

No-op if target is undefined.

FromEventRuleArn(Construct, string, string)

Import an existing EventBridge Rule provided an ARN.

public static IRule FromEventRuleArn(Construct scope, string id, string eventRuleArn)
Parameters
scope Construct

The parent creating construct (usually this).

id string

The construct's name.

eventRuleArn string

Event Rule ARN (i.e. arn:aws:events:<region>:<account-id>:rule/MyScheduledRule).

Returns

IRule

Remarks

Resource: AWS::Events::Rule

ExampleMetadata: infused

ValidateRule()

Defines an EventBridge Rule in this stack.

protected virtual string[] ValidateRule()
Returns

string[]

Remarks

Resource: AWS::Events::Rule

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

Implements

IRule
IResource
IRuleRef
Constructs.IConstruct
Constructs.IDependable
IEnvironmentAware
Back to top Generated by DocFX