【问题标题】:How do I create an ECS Service using AWS CDK in a VPC with more than 16 subnets如何在具有超过 16 个子网的 VPC 中使用 AWS CDK 创建 ECS 服务
【发布时间】:2019-10-19 10:07:28
【问题描述】:

使用 AWS CDK 创建 FargateService 时,我收到以下错误:

子网最多可以有 16 个项目。

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

 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 吗?
  • 是的,导入现有 VPC。目前,我正在努力将 VPC 中的子网数量减少到 16 个以下的限制

标签: aws-cdk


【解决方案1】:

如果您要导入现有 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 个公有子网。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-15
    • 2020-11-05
    • 1970-01-01
    • 2019-01-29
    • 2021-06-08
    • 1970-01-01
    • 2016-08-16
    相关资源
    最近更新 更多