“ elb名称长于32”但只有8

Lud*_*udo 0 amazon-ecs aws-cloudformation

我正在尝试使用AWS cloudformation创建具有ALB和ECS服务的堆栈,但是我在CREATE_FAILED上看到了AWS::ECS::Service,这是elb name longer than 32

我不明白为什么当ALB本身处于CREATE_COMPLETE状态时ECS服务抱怨ELB名称…

这是与我发送到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" }
        ]
      }
    }
Run Code Online (Sandbox Code Playgroud)

这是与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"
        }
      }
    }
Run Code Online (Sandbox Code Playgroud)

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

Sud*_*ran 5

When you do "Ref", it would return the Load balancer ARN not the Load balancer name. you need to use GetAtt to get the load balancer name

{ "Fn::GetAtt" : [ "loadBalancer", "LoadBalancerName" ] }
Run Code Online (Sandbox Code Playgroud)