【问题标题】:Cloudformation in create stack error: "ELB cannot be attached to multiple subnets in the same AZ"Cloudformation 在创建堆栈错误:“ELB 不能附加到同一 AZ 中的多个子网”
【发布时间】:2016-04-09 02:59:52
【问题描述】:

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

CREATE_FAILED AWS::ElasticLoadBalancing::LoadBalancer Rest ELB 不能 连接到同一个 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"
            }
        }
    }

我做错了什么?

谢谢!

【问题讨论】:

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


    【解决方案1】:
    "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" }]
    

    【讨论】:

    • 它仍然没有帮助我。我收到错误:“指定子网的可用区与 AutoScalingGroup 不匹配”
    • @muzaparoff 我看到你在写下它没有帮助之后接受了答案。你还有这个问题吗?
    • 它帮助我得到了关于子网和 AutoscalingGroup 中的可用区的另一个错误。我也修复了它。所以现在一切都很好。谢谢!
    • 此错误也可能发生,如 docs.aws.amazon.com/elasticbeanstalk/latest/dg/… 所述,“更改负载均衡器上的子网需要将其移出原始可用区,然后返回到具有所需子网的原始可用区。在在这个过程中,你所有的实例都会在 AZ 之间迁移,导致大量停机。如果你需要使用不同的子网,最好创建一个新的环境并执行 CNAME 交换。”
    猜你喜欢
    • 1970-01-01
    • 2019-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-20
    • 1970-01-01
    相关资源
    最近更新 更多