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

2

0

What can I do here?

I am getting this error:

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'?

My code:

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" },
        },

when tried securityGroups: dbClusterSecurityGroup, getting error :

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'

Updating my question:

securityGroups: [dbClusterSecurityGroup] this worked but now getting errors

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

Error is:

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'
Traveler answered 27/10, 2021 at 4:29 Comment(1)
securityGroups: [dbClusterSecurityGroup]Cappuccino
B
1

Start with checking the documentation:

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

As you can see, InstanceProps doesn't have a securityGroup parameter, just securityGroups, which accepts an array of ISecurityGroup objects, not just one ISecurityGroup, which you're passing. This is how it should look like:

securityGroups: [dbClusterSecurityGroup]
Bram answered 27/10, 2021 at 10:32 Comment(7)
Argument of type '{ backup: { preferredWindow: string; retention: cdk.Duration; }; defaultDatabaseName: string; engineVersion: string; instanceProps: { instanceType: ec2.InstanceType; securityGroups: ec2.SecurityGroup[]; vpc: ec2.IVpc; vpcSubnets: { ...; }; }; ... 6 more ...; storageEncrypted: true; }' is not assignable to parameter of type 'DatabaseClusterProps'. Object literal may only specify known properties, and 'engineVersion' does not exist in type 'DatabaseClusterProps'.ts(2345)Traveler
securityGroups: [dbClusterSecurityGroup] this worked but it gave the above errorTraveler
error shows: engineVersion: string[]; so I tried engineVersion: [postgresDatabaseEngineVersion], but still same error 'engineVersion' does not exist in type 'DatabaseClusterProps'Traveler
need help what should these 2 vaules be ? engine: [ rds.DatabaseClusterEngine.auroraPostgres ], engineVersion: [ rds.AuroraPostgresEngineVersion.VER_13_3 ],Traveler
Did you check the documentation? Does DatabaseClusterProps have an engineVerision property?Bram
yes but docs seems to bit tough to understand as it doesn't have a sample example to understand it easily, as I am lacking knowledge of typescript coding.Traveler
No, DatabaseClusterProps does not have an engineVersion property.Bram
M
1

I had the same issue when importing from different packages.

import * as iam from '@aws-cdk/aws-iam';
import { Effect } from 'aws-cdk-lib/aws-iam';

Fix:

import { Effect } from 'aws-cdk-lib/aws-iam';
import * as iam from 'aws-cdk-lib/aws-iam';
Murton answered 11/10, 2023 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.