Rule L2 construct
Defines an EventBridge Rule in this stack.
Example
import * as redshiftserverless from 'aws-cdk-lib/aws-redshiftserverless'
declare const workgroup: redshiftserverless.CfnWorkgroup;
const rule = new events.Rule(this, 'Rule', {
schedule: events.Schedule.rate(cdk.Duration.hours(1)),
});
const dlq = new sqs.Queue(this, 'DeadLetterQueue');
rule.addTarget(new targets.RedshiftQuery(workgroup.attrWorkgroupWorkgroupArn, {
database: 'dev',
deadLetterQueue: dlq,
sql: ['SELECT * FROM foo','SELECT * FROM baz'],
}));
import aws_cdk.aws_redshiftserverless as redshiftserverless
# workgroup: redshiftserverless.CfnWorkgroup
rule = events.Rule(self, "Rule",
schedule=events.Schedule.rate(cdk.Duration.hours(1))
)
dlq = sqs.Queue(self, "DeadLetterQueue")
rule.add_target(targets.RedshiftQuery(workgroup.attr_workgroup_workgroup_arn,
database="dev",
dead_letter_queue=dlq,
sql=["SELECT * FROM foo", "SELECT * FROM baz"]
))
import software.amazon.awscdk.services.redshiftserverless.*;
CfnWorkgroup workgroup;
Rule rule = Rule.Builder.create(this, "Rule")
.schedule(Schedule.rate(Duration.hours(1)))
.build();
Queue dlq = new Queue(this, "DeadLetterQueue");
rule.addTarget(RedshiftQuery.Builder.create(workgroup.getAttrWorkgroupWorkgroupArn())
.database("dev")
.deadLetterQueue(dlq)
.sql(List.of("SELECT * FROM foo", "SELECT * FROM baz"))
.build());
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.RedshiftServerless;
CfnWorkgroup workgroup;
var rule = new Rule(this, "Rule", new RuleProps {
Schedule = Schedule.Rate(Duration.Hours(1))
});
var dlq = new Queue(this, "DeadLetterQueue");
rule.AddTarget(new RedshiftQuery(workgroup.AttrWorkgroupWorkgroupArn, new RedshiftQueryProps {
Database = "dev",
DeadLetterQueue = dlq,
Sql = new [] { "SELECT * FROM foo", "SELECT * FROM baz" }
}));
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import redshiftserverless "github.com/aws/aws-cdk-go/awscdk"
var workgroup CfnWorkgroup
rule := events.NewRule(this, jsii.String("Rule"), &RuleProps{
Schedule: events.Schedule_Rate(cdk.Duration_Hours(jsii.Number(1))),
})
dlq := sqs.NewQueue(this, jsii.String("DeadLetterQueue"))
rule.AddTarget(targets.NewRedshiftQuery(workgroup.attrWorkgroupWorkgroupArn, &RedshiftQueryProps{
Database: jsii.String("dev"),
DeadLetterQueue: dlq,
Sql: []*string{
jsii.String("SELECT * FROM foo"),
jsii.String("SELECT * FROM baz"),
},
}))
Initializer
Construct Props
crossStackScopeConstructcross_stack_scopeConstructcrossStackScopeConstructCrossStackScopeConstructCrossStackScopeConstruct= none (the main scope will be use…#This helps dealing with cycles that often arise in these situations.
default
Default: none (the main scope will be used, even for cross-stack Events)
descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string= No description#eventBusIEventBusRefevent_busIEventBusRefeventBusIEventBusRefEventBusIEventBusRefEventBusIEventBusRef= The default event bus.#eventPatternEventPatternevent_patternEventPatterneventPatternEventPatternEventPatternEventPatternEventPatternEventPattern= No additional filtering based on…#The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering.
default
Default: No additional filtering based on an event pattern.
Must be assumable by principal events.amazonaws.com.
ruleNamestringrule_namestrruleNameStringRuleNamestringRuleName*string= AWS CloudFormation generates a u…#default
Default: AWS CloudFormation generates a unique physical ID.
You must specify this property, the eventPattern property, or both.
For more information, see Schedule Expression Syntax for Rules in the Amazon EventBridge User Guide.
targetsIRuleTarget[]targetstyping.List[IRuleTarget]targetsList<IRuleTarget>TargetsIRuleTarget[]Targets*[]IRuleTarget= No targets.#Input will be the full matched event. If you wish to specify custom target input, use addTarget(target[, inputOptions]).
Properties
envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironmentrequired#notes
For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#ruleRefRuleReferencerule_refRuleReferenceruleRefRuleReferenceRuleRefRuleReferenceRuleRefRuleReferencerequired#Methods
addEventPattern(eventPattern?: EventPattern): voiddef add_event_pattern(self, event_pattern: typing.Optional[EventPattern] = None) -> Nonepublic void addEventPattern(EventPattern eventPattern)public void AddEventPattern(EventPattern? eventPattern = null)func AddEventPattern(EventPattern EventPattern)#notes
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(target?: IRuleTarget): voiddef add_target(self, target: typing.Optional[IRuleTarget] = None) -> Nonepublic void addTarget(IRuleTarget target)public void AddTarget(IRuleTarget? target = null)func AddTarget(Target IRuleTarget)#No-op if target is undefined.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#notes · 1 parameter
When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.
Parameters
strengthstrengthstrengthstrengthStrength— - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#notes
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).
fromEventRuleArn(scope: Construct, id: string, eventRuleArn: string): IRule@staticmethod def from_event_rule_arn(scope: Construct, id: str, event_rule_arn: str) -> IRulepublic static IRule fromEventRuleArn(Construct scope, String id, String eventRuleArn)public static IRule FromEventRuleArn(Construct scope, string id, string eventRuleArn)func FromEventRuleArn(Scope Construct, Id *string, EventRuleArn *string) IRulestatic#3 parameters
Parameters
scopescopescopescopeScope— The parent creating construct (usuallythis).ididididId— The construct's name.eventRuleArnevent_rule_arneventRuleArneventRuleArnEventRuleArn— Event Rule ARN (i.e. arn:aws:events:<region>:<account-id>:rule/MyScheduledRule).
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.