json - 创建堆栈中的 Cloudformation 错误 : "ELB cannot be attached to multiple subnets in the same AZ"

标签 json amazon-web-services aws-cloudformation devops

我尝试使用 Cloudformation json 模板构建基础设施。当我在我需要的两个可用区中添加两个子网和 SubnetRouteTableAssociation 时。但创建过程无法创建负载均衡器,并出现错误:

CREATE_FAILED AWS::ElasticLoadBalancing::LoadBalancer Rest ELB cannot be attached to multiple subnets in the same AZ.

以下是可用区的参数:

"AZs" : {
            "Description" : "The list of AvailabilityZones.",
            "Type" : "CommaDelimitedList",
            "Default" : "us-east-1a,us-east-1c"
        }

以下是子网资源、两个可用区中的 SubnetRouteTableAssociation 以及 Rest 的 ElasticLoadBalancing:

"PublicSubnet1a" : {
      "Type" : "AWS::EC2::Subnet",
      "Properties" : {
        "VpcId" : { "Ref" : "VPC" },
        "CidrBlock" : "10.0.0.0/24",
        "AvailabilityZone": {
          "Fn::Select": ["1", { "Ref": "AZs" }]
        },
        "Tags" : [
          {"Key": "Name", "Value": {"Fn::Join": ["", ["Offering-", {"Ref": "Env"}, {"Ref": "EnvNum"}, "-VPC"]]}},
          {"Key" : "Network", "Value" : "Public" }
        ]
      }
    },
     "PublicSubnet1c" : {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "VpcId": { "Ref" : "VPC" },
        "CidrBlock": "10.0.1.0/24",
        "AvailabilityZone": {
          "Fn::Select": ["1", { "Ref": "AZs" }]
        },
        "Tags" : [
          {"Key": "Name", "Value": {"Fn::Join": ["", ["Offering-", {"Ref": "Env"}, {"Ref": "EnvNum"}, "-VPC"]]}},
          {"Key" : "Network", "Value" : "Public" }
        ]
      }
    },
"PublicSubnet1aRouteTableAssociation" : {
      "Type" : "AWS::EC2::SubnetRouteTableAssociation",
      "Properties" : {
        "SubnetId" : { "Ref" : "PublicSubnet1a" },
        "RouteTableId" : { "Ref" : "PublicRouteTable" }
      }
    },
    "PublicSubnet1cRouteTableAssociation" : {
      "Type" : "AWS::EC2::SubnetRouteTableAssociation",
      "Properties" : {
        "SubnetId" : { "Ref" : "PublicSubnet1c" },
        "RouteTableId" : { "Ref" : "PublicRouteTable" }
      }
    },
"RestELB" : {
        "Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
        "DependsOn": "AttachGateway",
        "Properties": {
            "LoadBalancerName": {"Fn::Join": ["",["Rest-ELB-", {"Ref": "VPC"}]]},
            "CrossZone" : "true",
            "Subnets": [{ "Ref": "PublicSubnet1a" },{ "Ref": "PublicSubnet1c" }],
            "Listeners" : [
                {"LoadBalancerPort" : "80", "InstancePort" : "80","Protocol" : "HTTP"},
                {"LoadBalancerPort" : "6060", "InstancePort" : "6060","Protocol" : "HTTP"}
            ],
            "HealthCheck" : {
              "Target" : "HTTP:80/",
              "HealthyThreshold" : "3",
              "UnhealthyThreshold" : "5",
              "Interval" : "90",
              "Timeout" : "60"
            }
        }
    }

我做错了什么?

谢谢!

最佳答案

"PublicSubnet1a" : {
    ...
    "AvailabilityZone": {
      "Fn::Select": ["1", { "Ref": "AZs" }] // <---- selects index 1 from AZs list
    },
    ...
"PublicSubnet1c" : {
    ...
    "AvailabilityZone": {
      "Fn::Select": ["1", { "Ref": "AZs" }] // <---- selects the same index 1 from AZs list
    },

您的两个子网都从 AZ 列表中选择相同的索引(请参阅“FN::select”语句)。将 PublicSubnet1a 的 select 语句更改为

"Fn::Select": ["0", { "Ref": "AZs" }]

关于json - 创建堆栈中的 Cloudformation 错误 : "ELB cannot be attached to multiple subnets in the same AZ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34609095/

相关文章:

amazon-s3 - 如何使用 AWS CDK(首选 typescript)向 API 网关的现有 AWS cloudfront 发行版添加行为?

amazon-web-services - 如何确认使用 CloudFormation 创建的订阅?

amazon-web-services - cdk部署是否等待完成部署?

php - iPhone-在 POST 中将 JSON 对象发送到 PHP 服务器并从服务器获取响应

json - 语法错误 : Unexpected token e in JSON at position 1 at JSON. 解析(<匿名>)

android - 在 Volley 中使用 JsonArrayRequest 时如何发布请求参数

amazon-web-services - 尝试在 AWS 的巴林(me-south-1) 区域设置 codepipeline

javascript - 显示使用 PHP 和 MySQL 创建的 JSON 数据

amazon-web-services - AWS CloudFormation 失败并出现错误 "Encountered unsupported property name"

amazon-web-services - 从AWS CDK中,我们如何获取当前的IAM用户?