Show / Hide Table of Contents

Class Rule

Defines an EventBridge Rule in this stack.

Inheritance
System.Object
Resource
Rule
Implements
IRule
IResource
Constructs.IConstruct
Constructs.IDependable
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
Syntax (vb)
Public Class Rule
    Inherits Resource
    Implements IRule, IResource
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(ByRefValue)

Used by jsii to construct an instance of this class from a Javascript-owned object reference

Rule(DeputyBase.DeputyProps)

Used by jsii to construct an instance of this class from DeputyProps

Rule(Construct, String, IRuleProps)

Properties

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.

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

Constructors

Rule(ByRefValue)

Used by jsii to construct an instance of this class from a Javascript-owned object reference

protected Rule(ByRefValue reference)
Parameters
reference Amazon.JSII.Runtime.Deputy.ByRefValue

The Javascript-owned object reference

Rule(DeputyBase.DeputyProps)

Used by jsii to construct an instance of this class from DeputyProps

protected Rule(DeputyBase.DeputyProps props)
Parameters
props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps

The deputy props

Rule(Construct, String, IRuleProps)

public Rule(Construct scope, string id, IRuleProps props = null)
Parameters
scope Constructs.Construct
id System.String
props IRuleProps

Properties

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

System.String

RuleName

The name event rule.

public virtual string RuleName { get; }
Property Value

System.String

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 Constructs.Construct

The parent creating construct (usually this).

id System.String

The construct's name.

eventRuleArn System.String

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

Returns

IRule

ValidateRule()

protected virtual string[] ValidateRule()
Returns

System.String[]

Implements

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