Cloudformation in create stack error: "ELB cannot be attached to multiple subnets in the same AZ"

Cloudformation in create stack error: "ELB cannot be attached to multiple subnets in the same AZ"

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

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

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
    },

您的两个子网 select 在可用区列表的同一索引中(参见 "FN::select" 声明)。将 PublicSubnet1a 的 select 语句更改为

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