5

我正在将我的 CDK 堆栈从 0.30.0 移植到 0.39.0。我有一个来自我的 AWS 账户的预定义 VPC,我只是将它导入到堆栈中。相同的子网在 0.30.0 中运行良好,但在 0.39.0 中出现错误消息:

“此 VPC 中没有‘公共’子网。使用不同的 VPC 子网选择。”

我的堆栈中有一个 VPC 和 3 个子网。我还有一个通往 dynamodb 和 s3 的网关。

有人遇到过这个问题吗?

除了导入 VPC,我尝试删除所有其他代码。

在 0.30.0 中,我使用这些行并且没有问题。

vpc = ec2.VpcNetwork.import(this, 'myvpc', {
  vpcId: 'vpc-xxxxxxxxxxxxxxxx',
  availabilityZones: ['ap-southeast-2a','ap-southeast-2b','ap-southeast-2c'],
  privateSubnetIds: ['subnet-xxxxxxxxxxxx', 'subnet-xxxxxxxxxxxx', 'subnet-xxxxxxxxxxxx']
});

在 0.39.0 中,我将其更改为:

vpc = ec2.Vpc.fromVpcAttributes(this, 'myvpc', {
  vpcId: "vpc-xxxxxxxxxxxxxxxx",
  availabilityZones: ['ap-southeast-2a','ap-southeast-2b','ap-southeast-2c'],
  privateSubnetIds: ['subnet-xxxxxxxxxxxx', 'subnet-xxxxxxxxxxxx', 'subnet-xxxxxxxxxxxx']
});
4

2 回答 2

3

我今天了解到 cdk 希望标记公共子网。说真的,即使从 cdk 1.5.0 开始,您也需要:

标签:键:aws-cdk:子网类型值:公共

于 2019-08-22T16:40:08.930 回答
0

我需要指定在导入 vpc 期间要使用的子网:

const vpc = ec2.Vpc.fromLookup(this, "vpc", {
                vpcName: props.vpcName,
                isDefault: (!props.vpcName),
                subnetGroupNameTag: "Public subnet"
            })
于 2020-10-07T07:30:50.247 回答