AWS CDK Typescript 问题:预期类型来自 属性 'securityGroups',它在此处声明为类型 'InstanceProps'

AWS CDK Typescript issue: The expected type comes from property 'securityGroups' which is declared here on type 'InstanceProps'

我可以在这里做什么?

我收到这个错误:

Type '{ instanceType: ec2.InstanceType; securityGroup: ec2.SecurityGroup; vpc: ec2.IVpc; vpcSubnets: { subnetName: string; }; }' is not assignable to type 'InstanceProps'.
  Object literal may only specify known properties, but 'securityGroup' does not exist in type 'InstanceProps'. Did you mean to write 'securityGroups'?

我的代码:

const dbClusterSecurityGroup = new ec2.SecurityGroup(this, "dbClusterSg", {
      allowAllOutbound: true,
      description: `Project ${projectName} Service database cluster`,
      securityGroupName: `${projectName}Database`,
      vpc,
    });
    dbClusterSecurityGroup.node.applyAspect(new cdk.Tag("Name", "serviceDatabaseCluster"));
    dbClusterSecurityGroup.addIngressRule(
      vpnSG,
      ec2.Port.tcp(postgresDatabasePort),
    );
    dbClusterSecurityGroup.addIngressRule(
      codeBuildProjectSG,
      ec2.Port.tcp(postgresDatabasePort),
    );
if (activeRegion === this.region) {
      const postgresCluster = new rds.DatabaseCluster(this, "dbCluster", {
        backup: {
          preferredWindow: "05:00-06:00",
          retention: cdk.Duration.days(30),
        },
        defaultDatabaseName: postgresDatabaseName,
         engine: [ rds.DatabaseClusterEngine.auroraPostgres ],
         engineVersion: [ rds.AuroraPostgresEngineVersion.VER_13_3 ],
        engineVersion: postgresDatabaseEngineVersion,
        instanceProps: {
          instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MEDIUM),
          *securityGroup: dbClusterSecurityGroup,*
          vpc,
          vpcSubnets: { subnetName: "data" },
        },

尝试安全组时:dbClusterSecurityGroup, 出现错误:

Type 'SecurityGroup' is missing the following properties from type 'ISecurityGroup[]': length, pop, push, concat, and 26 more.
The expected type comes from property 'securityGroups' which is declared here on type 'InstanceProps'

更新我的问题:

securityGroups:[dbClusterSecurityGroup] 这有效但现在出现错误

 engine: [ rds.DatabaseClusterEngine.auroraPostgres ],
 engineVersion: [ rds.AuroraPostgresEngineVersion.VER_13_3 ],

错误是:

TSError: ⨯ Unable to compile TypeScript:
lib/database-stack.ts:120:9 - error TS2739: Type '((props: AuroraPostgresClusterEngineProps) => IClusterEngine)[]' is missing the following properties from type 'IClusterEngine': singleUserRotationApplication, multiUserRotationApplication, supportedLogTypes, bindToCluster, engineType

120         engine: [ rds.DatabaseClusterEngine.auroraPostgres ],
            ~~~~~~

  node_modules/@aws-cdk/aws-rds/lib/cluster.d.ts:26:14
    26     readonly engine: IClusterEngine;
                    ~~~~~~
    The expected type comes from property 'engine' which is declared here on type 'DatabaseClusterProps'

从检查文档开始:

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-rds.InstanceProps.html

如您所见,InstanceProps 没有 securityGroup 参数,只有 securityGroups,它接受 array ISecurityGroup 个对象,而不仅仅是您传递的一个 ISecurityGroup。它应该是这样的:

securityGroups: [dbClusterSecurityGroup]