我正在尝试在现有 VPC 上创建 Fargate ECS 服务,但运行后出现以下错误cdk deploy
CREATE_FAILED | AWS::ElasticLoadBalancingV2::LoadBalancer | exms-service/LB (exmsserviceLB259DA1C7) At least two subnets in two different Availability Zones must be specified (Service: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: ValidationError;
vpc导入正确,根据cloudformation日志创建ecs集群成功。创建负载均衡器时发生故障
const vpc = ec2.VpcNetwork.import(this, "TB-DEV", {
vpcId: 'vpc-xxxxxx',
availabilityZones: ['eu-west-1G', 'eu-west-1b', 'eu-west-1c'],
privateSubnetIds: ['subnet-xxxxxxx', 'subnet-xxxxx', 'subnet-xxxx', 'subnet-xxxxx', 'subnet-xxxxx', 'subnet-xxxxx']
//this is a list of 1 private and 1 public subnet on each of the specified availability zones
})
const cluster = new ecs.Cluster(this, "TB-ECS-DEV", {
clusterName: "TB-DEV",
vpc: vpc,
})
const repo = ecr.Repository.import(this, 'EXMS-REPO', {
repositoryName: "expense-type-mapper-dev"
})
new ecs.LoadBalancedFargateService(this, "EXMS", {
cluster: cluster,
image:ecs.ContainerImage.fromEcrRepository(repo),
})
我希望负载均衡器使用 VPC 定义中指定的子网,但这似乎没有发生。我是否需要在 LoadBalancedFargateService 定义的某处定义要使用的子网?