" elb名称超过32"但只有8个

时间:2018-02-28 13:24:23

标签: amazon-cloudformation amazon-ecs

我正在尝试使用AWS cloudformation来创建一个包含ALB和ECS服务的堆栈,但我在CREATE_FAILED上获得AWS::ECS::Service,即elb name longer than 32

我不明白为什么ECS服务抱怨ELB名称,而ALB本身处于CREATE_COMPLETE状态...

以下是与发送给cloudformation的ALB创建相关的JSON:

    "loadBalancer" : {
      "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
      "Properties": {
        "Name": "test-alb",
        "Scheme" : "internal",
        "Subnets" : [
          "subnet-b8217295",
          "subnet-ddaad2b8",
          "subnet-6d71fb51"
        ],
        "LoadBalancerAttributes" : [
          { "Key" : "idle_timeout.timeout_seconds", "Value" : "50" }
        ],
        "SecurityGroups": [
          { "Ref": "InstanceSecurityGroupOpenWeb" },
          { "Ref" : "InstanceSecurityGroupOpenFull" }
        ],
        "Tags" : [
          { "Key" : "key", "Value" : "value" },
          { "Key" : "key2", "Value" : "value2" }
        ]
      }
    }

以下是与ECS服务创建相关的JSON(以及上面定义的ALB的参考):

    "EcsService": {
      "Type":"AWS::ECS::Service",
      "Properties":{
        "Cluster":{
          "Ref": "EcsCluster"
        },
        "DesiredCount":"1",
        "DeploymentConfiguration":{
          "MaximumPercent":100,
          "MinimumHealthyPercent":0
        },
        "LoadBalancers": [
          {
            "ContainerName": "test-web",
            "ContainerPort":"80",
            "LoadBalancerName":{
              "Ref": "loadBalancer"
            }
          }
        ],
        "Role":{
          "Ref": "EcsServiceRole"
        },
        "TaskDefinition":{
          "Ref": "runWebServerTaskDefinition"
        }
      }
    }

正如你所看到我自己设置了ALB的名称,它只有8个字符,所以我真的不明白这一点,任何想法?

1 个答案:

答案 0 :(得分:4)

执行"Ref"时,它将返回负载均衡器ARN而不是负载均衡器名称。您需要使用GetAtt来获取负载均衡器名称

{ "Fn::GetAtt" : [ "loadBalancer", "LoadBalancerName" ] }