Reputation: 301
I am trying to add target to an existing event rule using aws cdk. but its throwing an error saying 'AddTarget' is not defined for IRule. I tried to cast IRule to Rule, still it didn't work for me.
IRule myRule = Rule.FromEventRuleArn(this, ruleId, ruleArn);
myRule.AddTarget(new LambdaFunction(myLambda, new LambdaFunctionProps
{
Event = RuleTargetInput.FromObject(myEvent)
}));
Upvotes: 1
Views: 596
Reputation: 25779
I am trying to add target to an existing event rule
That's not going to work. AddTarget
needs to *modify* the rule resource. But an IRule
is read-only. The ISomething
"interface" types are bare-bones subsets of Something
types, that permit read-only referencing of resources external to the CDK App.
I tried to cast IRule to Rule, still it didn't work for me
That's not going to help. Rule
implements IRule
, not the other way around.
Upvotes: 1