本文介绍了AWS CDK Typescript 问题:预期类型来自属性“securityGroups",该属性在此处声明为“InstanceProps"类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道该怎么做,感谢您的帮助!
I am not sure what to do, any help is appreciated!
获取错误:
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: "aurora",
//engine: rds.DatabaseInstanceEngine.AURORA_POSTGRESQL,
engineVersion: postgresDatabaseEngineVersion,
instanceProps: {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MEDIUM),
*securityGroup: dbClusterSecurityGroup,*
vpc,
vpcSubnets: { subnetName: "data" },
},
当尝试 securityGroups: dbClusterSecurityGroup,收到错误:
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'
推荐答案
从检查文档开始:
https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-rds.InstanceProps.html
如你所见,InstanceProps
没有 securityGroup
参数,只有 securityGroups
,它接受一个 sequence 个 ISecurityGroup
对象,而不仅仅是一个 ISecurityGroup
,你正在传递.
As you can see, InstanceProps
doesn't have a securityGroup
parameter, just securityGroups
, which accepts a sequence of ISecurityGroup
objects, not just one ISecurityGroup
, which you're passing.
这篇关于AWS CDK Typescript 问题:预期类型来自属性“securityGroups",该属性在此处声明为“InstanceProps"类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!