我对 aws 的 typescript CDK 相当陌生,并且正在尝试在 typescript 中使用 CDK 部署一个 lambda 函数,如下所示:
const lambdaFn = new lambda.Function(..);
现在,我正在尝试创建一个需要触发此 lambda 函数的事件规则。当我targets
在规则中添加部分(如下所示)时,我看到如下所示的错误。
const rule = new events.Rule(
this,
'Rule',
{
eventPattern: {"source": [ "aws.organizations" ], "detail": { "eventName": [ "CreateAccountResult" ] } },
targets: [ new targets.LambdaFunction(lambdaFn) ] // <<<--- this line throws exceptions..
}
);
我看到的例外:
lib/test.ts:26:20 - error TS2322: Type 'LambdaFunction' is not assignable to type 'IRuleTarget'.
Types of property 'bind' are incompatible.
Type '(rule: IRule, _id?: string | undefined) => RuleTargetConfig' is not assignable to type '(rule: IRule, id?: string | undefined) => RuleTargetConfig'.
Types of parameters 'rule' and 'rule' are incompatible.
26 targets: [ new targets.LambdaFunction(lambdaFn) ]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
..
..
..
lib/test.ts:26:47 - error TS2345: Argument of type 'Function' is not assignable to parameter of type 'IFunction'.
Types of property 'role' are incompatible.
Type 'import("/home/shubham/workspace/ft/organization-management-services/node_modules/@aws-cdk/aws-iam/lib/role").IRole | undefined' is not assignable to type 'import("/home/shubham/workspace/ft/organization
..
..
26 targets: [ new targets.LambdaFunction(lambdaFn) ]
~~~~~~~~
我错过了什么?