在 golang 中使用 CDK 将目标添加到 CloudWatch 事件规则

问题描述

我对 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) ]
                                                 ~~~~~~~~

我错过了什么?

解决方法

这是一个已知问题,记录在此处:https://github.com/aws-samples/aws-cdk-examples/issues/89

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...