gpt4 book ai didi

aws-cdk - 如何在具有超过 16 个子网的 VPC 中使用 AWS CDK 创建 ECS 服务

转载 作者:行者123 更新时间:2023-12-03 08:51:48 27 4
gpt4 key购买 nike

使用 AWS CDK 创建 FargateService 时,出现以下错误:

subnets can have at most 16 items.

我有这个代码来创建服务:

 var ecsService = new FargateService(this, $"{serviceNameHyphen}-service", new FargateServiceProps
{
TaskDefinition = taskDefinition,
AssignPublicIp = false,
Cluster = infrastructureStack.EcsCluster,
CloudMapOptions = new CloudMapOptions
{
Name = serviceName,
DnsRecordType = DnsRecordType.A,
DnsTtl = Duration.Seconds(60),
FailureThreshold = 2d
},
DesiredCount = 1,
HealthCheckGracePeriod = Duration.Seconds(60),
MaxHealthyPercent = 200,
MinHealthyPercent = 100,
PlatformVersion = FargatePlatformVersion.LATEST,
ServiceName = $"{serviceNameHyphen}-service",
SecurityGroup = albSecurityGroup,
VpcSubnets = new SubnetSelection
{
OnePerAz = true,
SubnetType = SubnetType.PUBLIC,
}
});

子网可以过滤吗?

或者,SubnetSelection 类具有 SubnetGroup 属性 - 我知道某些 AWS 服务允许创建子网组,但我不知道如何创建子网组用于 Fargate 服务的任意子网组。

更新我现在 VPC 中只有 15 个子网,但仍然收到相同的错误消息。

最佳答案

如果您要导入现有 VPC,则可以通过使用 ec2.Vpc.fromVpcAttributes()(而不是使用 ec2.Vpc.fromLookup())导入子网子集来解决此问题:

const vpc = ec2.Vpc.fromVpcAttributes(this, 'Vpc', {
vpcId: 'vpc-xxxxxxxx',
availabilityZones: ['eu-west-1a', 'eu-west-1b', 'eu-west-1c'],
publicSubnetIds: ['subnet-xxxxxxxx', 'subnet-xxxxxxxx', 'subnet-xxxxxxxx'],
privateSubnetIds: ['subnet-xxxxxxxx', 'subnet-xxxxxxxx', 'subnet-xxxxxxxx']
});

这样,从 CDK 应用程序的角度来看,您的 VPC 将只有 3 个公有子网。

关于aws-cdk - 如何在具有超过 16 个子网的 VPC 中使用 AWS CDK 创建 ECS 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58462571/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com