Amazon cloudformation AWS Fargate-实例启动时运行状况检查失败

Amazon cloudformation AWS Fargate-实例启动时运行状况检查失败,amazon-cloudformation,aws-fargate,Amazon Cloudformation,Aws Fargate,我是一个类似的问题,一些职位,但没有具体的问题,因为我可以告诉。我将在稍后的文章中发布我的堆栈 我有: ALB----->Listener->target group->Fargate service->task definition 80/http ->8080/http -> 8080/http 问题是我的健康检查失败了。当Fargate任务启动一个实例时,我可以使用health check URL

我是一个类似的问题,一些职位,但没有具体的问题,因为我可以告诉。我将在稍后的文章中发布我的堆栈

我有:

ALB----->Listener->target group->Fargate service->task definition
80/http           ->8080/http                   -> 8080/http
问题是我的健康检查失败了。当Fargate任务启动一个实例时,我可以使用health check URL访问该实例,得到一个200响应。但是,任何尝试通过负载平衡器的行为都会导致网关超时

$ curl -fv http://172.31.47.18:8080/healthz
*   Trying 172.31.47.18...
* TCP_NODELAY set
* Connected to 172.31.47.18 (172.31.47.18) port 8080 (#0)
> GET /healthz HTTP/1.1
> Host: 172.31.47.18:8080
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Transfer-Encoding: chunked
< Date: Sun, 24 Nov 2019 15:33:39 GMT
< Server: Warp/3.2.27
< 
* Connection #0 to host 172.31.47.18 left intact
OK
希望有人有主意

  TaskDef0:
    Type: AWS::ECS::TaskDefinition
    DependsOn: Cluster0
    Properties:
      ExecutionRoleArn: arn:aws:iam::xxxxx:role/ECS_Hasura_Execution_Role
      TaskRoleArn: arn:aws:iam::xxxxx:role/ecsTaskExecutionRole
      Family: !Ref 'ServiceName'
      Cpu: !FindInMap
                - ContainerSizeMap
                - !Ref ContainerSize
                - Cpu
      Memory: !FindInMap
                   - ContainerSizeMap
                   - !Ref ContainerSize
                   - Memory
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - FARGATE
      ContainerDefinitions:
        - Name: !Ref 'ServiceName'
          Cpu: !FindInMap
                - ContainerSizeMap
                - !Ref ContainerSize
                - Cpu
          Memory: !FindInMap
                   - ContainerSizeMap
                   - !Ref ContainerSize
                   - Memory
          Image: !FindInMap
                - ServiceMap
                - !Ref ServiceProvider
                - ImageUrl
          PortMappings:
            - 
              ContainerPort: !Ref 'ContainerPort'
              HostPort: !Ref ContainerPort
              Protocol: tcp

  ALB0:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    DependsOn: TaskDef0
    Properties: 
      Name: !Join
              - '-'
              - - lb-
                - !Ref ServiceName
      Scheme: internet-facing
      IpAddressType: ipv4
      LoadBalancerAttributes: 
        - Key: deletion_protection.enabled
          Value: false
        - Key: idle_timeout.timeout_seconds
          Value: 60
        - Key: routing.http.drop_invalid_header_fields.enabled
          Value: false
        - Key: routing.http2.enabled
          Value: true
      SecurityGroups: 
        - sg-xxxxxx # allow HTTP/HTTPS to the load balancer
      Subnets: 
        - subnet-111111
        - subnet-222222
        - subnet-333333
      Type: application

  targetGroup0:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    DependsOn: ALB0
    Properties: 
      Name: !Join
              - '-'
              - - tg-
                - !Ref ServiceName
      Port: !Ref TargetGroupPort
      Protocol: !Ref TargetGroupProtocol    
      TargetType: ip
      VpcId: !FindInMap
                - ServiceMap
                - !Ref ServiceProvider
                - VpcId
      # all other paraneters can be changed without interruption
      HealthCheckPort: traffic-port
      HealthCheckEnabled: !FindInMap
                - LBTGMap
                - Parameters
                - HealthCheckEnabled
      HealthCheckIntervalSeconds: !FindInMap
                - LBTGMap
                - Parameters
                - HealthCheckIntervalSeconds
      HealthCheckPath: !FindInMap
                - ServiceMap
                - !Ref ServiceProvider
                - HealthCheckPath
      HealthCheckProtocol: !FindInMap
                - ServiceMap
                - !Ref ServiceProvider
                - HealthCheckProtocol
      HealthCheckTimeoutSeconds: !FindInMap
                - LBTGMap
                - Parameters
                - HealthCheckTimeoutSeconds
      HealthyThresholdCount: !FindInMap
                - LBTGMap
                - Parameters
                - HealthyThresholdCount
      UnhealthyThresholdCount: !FindInMap
                - LBTGMap
                - Parameters
                - UnhealthyThresholdCount
      Matcher: 
        HttpCode: !FindInMap
                - ServiceMap
                - !Ref ServiceProvider
                - HealthCheckSuccessCode
      TargetGroupAttributes: 
        - Key: deregistration_delay.timeout_seconds
          Value: !FindInMap
                - LBTGMap
                - Parameters
                - DeregistrationDelay
        - Key: slow_start.duration_seconds
          Value: !FindInMap
                - LBTGMap
                - Parameters
                - SlowStart
        - Key: stickiness.enabled
          Value: !FindInMap
                - LBTGMap
                - Parameters
                - Stickiness

  Listener0:
    # This is the fixed response test listener
    Type: AWS::ElasticLoadBalancingV2::Listener
    DependsOn: ALB0
    Properties:   
      DefaultActions: 
        - Type: fixed-response      
          FixedResponseConfig: 
            ContentType: text/html
            MessageBody: <h1>Working</h1><p>The load balancer test listener is operational</p>
            StatusCode: 200
      LoadBalancerArn: !Ref ALB0
      Port: 9000
      Protocol: HTTP

  Listener1:
    # This is the port 80 listener
    Type: AWS::ElasticLoadBalancingV2::Listener
    DependsOn: ALB0
    Properties:   
      DefaultActions: 
        - Type: forward
          TargetGroupArn: !Ref targetGroup0
      LoadBalancerArn: !Ref ALB0
      Port: 80
      Protocol: HTTP

  Listener2:
    # This is the port 8080 listener
    Type: AWS::ElasticLoadBalancingV2::Listener
    DependsOn: ALB0
    Properties:   
      DefaultActions: 
        - Type: forward
          TargetGroupArn: !Ref targetGroup0
      LoadBalancerArn: !Ref ALB0
      Port: 8080
      Protocol: HTTP

  Listener3 :
    # This is the port 443 listener
    Type: AWS::ElasticLoadBalancingV2::Listener
    DependsOn: ALB0
    Properties:   
      Certificates:
        - CertificateArn: !FindInMap
                - CertificateMap
                - !Ref AWS::Region
                - CertifcateArn  
      DefaultActions: 
        - Type: forward
          TargetGroupArn: !Ref targetGroup0
      LoadBalancerArn: !Ref ALB0
      Port: 443
      Protocol: HTTPS

  Service0:
    Type: AWS::ECS::Service
    DependsOn: Listener2
    Properties:
      ServiceName: !Ref 'ServiceName'
      Cluster: !Ref Cluster0
      LaunchType: FARGATE
      DeploymentConfiguration:
        MaximumPercent: !FindInMap
                - ECSServiceMap
                - Parameters
                - MaximumPercent
        MinimumHealthyPercent: !FindInMap
                - ECSServiceMap
                - Parameters
                - MinimumHealthyPercent
      DesiredCount: !Ref 'DesiredTaskCount'
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: ENABLED
          SecurityGroups: # this is allow all ports and IPs
            - !FindInMap
                - SecurityGroupMap
                - !Ref AWS::Region
                - sg0
          Subnets:
            - !FindInMap
                - SubnetMap
                - !Ref AWS::Region
                - subnet0
            - !FindInMap
                - SubnetMap
                - !Ref AWS::Region
                - subnet1
            - !FindInMap
                - SubnetMap
                - !Ref AWS::Region
                - subnet2
      TaskDefinition: !Ref 'TaskDef0'
      LoadBalancers:
        - ContainerName: !Ref 'ServiceName'
          ContainerPort: !Ref 'ContainerPort'
          TargetGroupArn: !Ref 'targetGroup0'
      Tags: 
        - Key: Application
          Value: !Ref "Application"
        - Key: Customer
          Value: !Ref "Customer"
        - Key: Role
          Value: !Ref "Role"
        - Key: InternetAccessible
          Value: !Ref "InternetAccessible"
        - Key: CreationDate
          Value: !Ref "CreationDate"
        - Key: CreatedBy
          Value: !Ref "CreatedBy"

Mappings:
  ServiceMap:
    GraphQL-Ohio: 
      ImageUrl: xxxxx.dkr.ecr.us-east-2.amazonaws.com/hasura/graphql-engine
      HealthCheckPath: /healthz
      HealthCheckSuccessCode: 200
      HealthCheckProtocol: HTTP
      VpcId: vpc-xxxxx

  LBTGMap:
    Parameters:
      HealthCheckEnabled: True
      HealthCheckIntervalSeconds: 30
      HealthCheckTimeoutSeconds: 5
      HealthyThresholdCount: 5
      UnhealthyThresholdCount: 2
      DeregistrationDelay: 300
      SlowStart: 0
      Stickiness: false

  SubnetMap: # There is technical debt here to keep this up to date as subnets change
    us-east-2:
      subnet0: subnet-111111
      subnet1: subnet-222222
      subnet2: subnet-333333

  SecurityGroupMap: 
    us-east-2: 
      sg0: sg-xxxxx
TaskDef0:
类型:AWS::ECS::TaskDefinition
DependsOn:Cluster0
特性:
执行角色学习:arn:aws:iam::xxxxx:role/ECS\u Hasura\u Execution\u role
TaskRoleArn:arn:aws:iam::xxxxx:角色/执行角色
家庭:!参考“ServiceName”
中央处理器:!FindInMap
-集装箱地图
- !参考集装箱化
-中央处理器
记忆:!FindInMap
-集装箱地图
- !参考集装箱化
-记忆
网络模式:awsvpc
要求符合性:
-法尔盖特
集装箱定义:
-姓名:!参考“ServiceName”
中央处理器:!FindInMap
-集装箱地图
- !参考集装箱化
-中央处理器
记忆:!FindInMap
-集装箱地图
- !参考集装箱化
-记忆
图片:!FindInMap
-服务地图
- !参考服务提供者
-图像URL
端口映射:
- 
集装箱港口:!参考“集装箱港口”
主机端口:!参考集装箱港口
协议:tcp
ALB0:
类型:AWS::ElasticLoadBalancingV2::负载平衡器
DependsOn:TaskDef0
特性:
姓名:!参加
- '-'
--磅-
- !参考服务名称
方案:面向互联网
IP地址类型:ipv4
LoadBalancer属性:
-密钥:删除\u保护已启用
值:false
-键:空闲\u超时。超时\u秒
价值:60
-关键字:routing.http.drop\u无效\u头\u字段。已启用
值:false
-密钥:routing.http2.enabled
值:true
安全组:
-sg-xxxxxx#允许HTTP/HTTPS连接到负载平衡器
子网:
-子网-111111
-子网-222222
-子网-333
类型:应用
目标群体0:
类型:AWS::ElasticLoadBalancingV2::TargetGroup
DependsOn:ALB0
特性:
姓名:!参加
- '-'
--tg-
- !参考服务名称
港口:!Ref TargetGroupPort
协议:!Ref TargetGroupProtocol
目标类型:ip
VpcId:!FindInMap
-服务地图
- !参考服务提供者
-VpcId
#所有其他妄想狂都可以不间断地改变
HealthCheckPort:交通端口
HealthCheckEnabled:!FindInMap
-LBTGMap
-参数
-HealthCheckEnabled
HealthCheckIntervalSeconds:!FindInMap
-LBTGMap
-参数
-HealthCheckIntervalSeconds
HealthCheckPath:!FindInMap
-服务地图
- !参考服务提供者
-健康检查路径
HealthCheckProtocol:!FindInMap
-服务地图
- !参考服务提供者
-健康检查协议
HealthCheckTimeoutSeconds:!FindInMap
-LBTGMap
-参数
-HealthCheckTimeoutSeconds
HealthThresholdCount:!FindInMap
-LBTGMap
-参数
-HealthThresholdCount
不健康thresholdcount:!FindInMap
-LBTGMap
-参数
-不健康的死亡人数
匹配器:
HttpCode:!FindInMap
-服务地图
- !参考服务提供者
-HealthCheckSuccessCode
TargetGroupAttributes:
-键:取消注册\u延迟。超时\u秒
值:!FindInMap
-LBTGMap
-参数
-撤销注册
-按键:慢速启动。持续时间\u秒
值:!FindInMap
-LBTGMap
-参数
-斯洛斯特
-键:粘性已启用
值:!FindInMap
-LBTGMap
-参数
-粘性
听众0:
#这是固定响应测试侦听器
类型:AWS::ElasticLoadBalancingV2::Listener
DependsOn:ALB0
特性:
默认操作:
-类型:固定响应
FixedResponseConfig:
ContentType:text/html
MessageBody:Working负载平衡器测试侦听器正在运行

状态代码:200 LoadBalancerArn:!参考ALB0 港口:9000 协议:HTTP 听众1: #这是端口80侦听器 类型:AWS::ElasticLoadBalancingV2::Listener DependsOn:ALB0 特性: 默认操作: -类型:前进 TargetGroupArn:!Ref targetGroup0 LoadBalancerArn:!参考ALB0 港口:80 协议:HTTP 听众2: #这是端口8080侦听器 类型:AWS::ElasticLoadBalancingV2::Listener DependsOn:ALB0 特性: 默认操作: -类型:前进 TargetGroupArn:!Ref targetGroup0 LoadBalancerArn:!参考ALB0 端口:8080 协议:HTTP 听众3: #这是端口443侦听器 类型:AWS::ElasticLoadBalancingV2::Listener DependsOn:ALB0 特性: 证书: -证书学习:!FindInMap -证书映射 - !Ref AWS::区域 -认证学习 默认操作: -类型:前进 T
  TaskDef0:
    Type: AWS::ECS::TaskDefinition
    DependsOn: Cluster0
    Properties:
      ExecutionRoleArn: arn:aws:iam::xxxxx:role/ECS_Hasura_Execution_Role
      TaskRoleArn: arn:aws:iam::xxxxx:role/ecsTaskExecutionRole
      Family: !Ref 'ServiceName'
      Cpu: !FindInMap
                - ContainerSizeMap
                - !Ref ContainerSize
                - Cpu
      Memory: !FindInMap
                   - ContainerSizeMap
                   - !Ref ContainerSize
                   - Memory
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - FARGATE
      ContainerDefinitions:
        - Name: !Ref 'ServiceName'
          Cpu: !FindInMap
                - ContainerSizeMap
                - !Ref ContainerSize
                - Cpu
          Memory: !FindInMap
                   - ContainerSizeMap
                   - !Ref ContainerSize
                   - Memory
          Image: !FindInMap
                - ServiceMap
                - !Ref ServiceProvider
                - ImageUrl
          PortMappings:
            - 
              ContainerPort: !Ref 'ContainerPort'
              HostPort: !Ref ContainerPort
              Protocol: tcp

  ALB0:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    DependsOn: TaskDef0
    Properties: 
      Name: !Join
              - '-'
              - - lb-
                - !Ref ServiceName
      Scheme: internet-facing
      IpAddressType: ipv4
      LoadBalancerAttributes: 
        - Key: deletion_protection.enabled
          Value: false
        - Key: idle_timeout.timeout_seconds
          Value: 60
        - Key: routing.http.drop_invalid_header_fields.enabled
          Value: false
        - Key: routing.http2.enabled
          Value: true
      SecurityGroups: 
        - sg-xxxxxx # allow HTTP/HTTPS to the load balancer
      Subnets: 
        - subnet-111111
        - subnet-222222
        - subnet-333333
      Type: application

  targetGroup0:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    DependsOn: ALB0
    Properties: 
      Name: !Join
              - '-'
              - - tg-
                - !Ref ServiceName
      Port: !Ref TargetGroupPort
      Protocol: !Ref TargetGroupProtocol    
      TargetType: ip
      VpcId: !FindInMap
                - ServiceMap
                - !Ref ServiceProvider
                - VpcId
      # all other paraneters can be changed without interruption
      HealthCheckPort: traffic-port
      HealthCheckEnabled: !FindInMap
                - LBTGMap
                - Parameters
                - HealthCheckEnabled
      HealthCheckIntervalSeconds: !FindInMap
                - LBTGMap
                - Parameters
                - HealthCheckIntervalSeconds
      HealthCheckPath: !FindInMap
                - ServiceMap
                - !Ref ServiceProvider
                - HealthCheckPath
      HealthCheckProtocol: !FindInMap
                - ServiceMap
                - !Ref ServiceProvider
                - HealthCheckProtocol
      HealthCheckTimeoutSeconds: !FindInMap
                - LBTGMap
                - Parameters
                - HealthCheckTimeoutSeconds
      HealthyThresholdCount: !FindInMap
                - LBTGMap
                - Parameters
                - HealthyThresholdCount
      UnhealthyThresholdCount: !FindInMap
                - LBTGMap
                - Parameters
                - UnhealthyThresholdCount
      Matcher: 
        HttpCode: !FindInMap
                - ServiceMap
                - !Ref ServiceProvider
                - HealthCheckSuccessCode
      TargetGroupAttributes: 
        - Key: deregistration_delay.timeout_seconds
          Value: !FindInMap
                - LBTGMap
                - Parameters
                - DeregistrationDelay
        - Key: slow_start.duration_seconds
          Value: !FindInMap
                - LBTGMap
                - Parameters
                - SlowStart
        - Key: stickiness.enabled
          Value: !FindInMap
                - LBTGMap
                - Parameters
                - Stickiness

  Listener0:
    # This is the fixed response test listener
    Type: AWS::ElasticLoadBalancingV2::Listener
    DependsOn: ALB0
    Properties:   
      DefaultActions: 
        - Type: fixed-response      
          FixedResponseConfig: 
            ContentType: text/html
            MessageBody: <h1>Working</h1><p>The load balancer test listener is operational</p>
            StatusCode: 200
      LoadBalancerArn: !Ref ALB0
      Port: 9000
      Protocol: HTTP

  Listener1:
    # This is the port 80 listener
    Type: AWS::ElasticLoadBalancingV2::Listener
    DependsOn: ALB0
    Properties:   
      DefaultActions: 
        - Type: forward
          TargetGroupArn: !Ref targetGroup0
      LoadBalancerArn: !Ref ALB0
      Port: 80
      Protocol: HTTP

  Listener2:
    # This is the port 8080 listener
    Type: AWS::ElasticLoadBalancingV2::Listener
    DependsOn: ALB0
    Properties:   
      DefaultActions: 
        - Type: forward
          TargetGroupArn: !Ref targetGroup0
      LoadBalancerArn: !Ref ALB0
      Port: 8080
      Protocol: HTTP

  Listener3 :
    # This is the port 443 listener
    Type: AWS::ElasticLoadBalancingV2::Listener
    DependsOn: ALB0
    Properties:   
      Certificates:
        - CertificateArn: !FindInMap
                - CertificateMap
                - !Ref AWS::Region
                - CertifcateArn  
      DefaultActions: 
        - Type: forward
          TargetGroupArn: !Ref targetGroup0
      LoadBalancerArn: !Ref ALB0
      Port: 443
      Protocol: HTTPS

  Service0:
    Type: AWS::ECS::Service
    DependsOn: Listener2
    Properties:
      ServiceName: !Ref 'ServiceName'
      Cluster: !Ref Cluster0
      LaunchType: FARGATE
      DeploymentConfiguration:
        MaximumPercent: !FindInMap
                - ECSServiceMap
                - Parameters
                - MaximumPercent
        MinimumHealthyPercent: !FindInMap
                - ECSServiceMap
                - Parameters
                - MinimumHealthyPercent
      DesiredCount: !Ref 'DesiredTaskCount'
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: ENABLED
          SecurityGroups: # this is allow all ports and IPs
            - !FindInMap
                - SecurityGroupMap
                - !Ref AWS::Region
                - sg0
          Subnets:
            - !FindInMap
                - SubnetMap
                - !Ref AWS::Region
                - subnet0
            - !FindInMap
                - SubnetMap
                - !Ref AWS::Region
                - subnet1
            - !FindInMap
                - SubnetMap
                - !Ref AWS::Region
                - subnet2
      TaskDefinition: !Ref 'TaskDef0'
      LoadBalancers:
        - ContainerName: !Ref 'ServiceName'
          ContainerPort: !Ref 'ContainerPort'
          TargetGroupArn: !Ref 'targetGroup0'
      Tags: 
        - Key: Application
          Value: !Ref "Application"
        - Key: Customer
          Value: !Ref "Customer"
        - Key: Role
          Value: !Ref "Role"
        - Key: InternetAccessible
          Value: !Ref "InternetAccessible"
        - Key: CreationDate
          Value: !Ref "CreationDate"
        - Key: CreatedBy
          Value: !Ref "CreatedBy"

Mappings:
  ServiceMap:
    GraphQL-Ohio: 
      ImageUrl: xxxxx.dkr.ecr.us-east-2.amazonaws.com/hasura/graphql-engine
      HealthCheckPath: /healthz
      HealthCheckSuccessCode: 200
      HealthCheckProtocol: HTTP
      VpcId: vpc-xxxxx

  LBTGMap:
    Parameters:
      HealthCheckEnabled: True
      HealthCheckIntervalSeconds: 30
      HealthCheckTimeoutSeconds: 5
      HealthyThresholdCount: 5
      UnhealthyThresholdCount: 2
      DeregistrationDelay: 300
      SlowStart: 0
      Stickiness: false

  SubnetMap: # There is technical debt here to keep this up to date as subnets change
    us-east-2:
      subnet0: subnet-111111
      subnet1: subnet-222222
      subnet2: subnet-333333

  SecurityGroupMap: 
    us-east-2: 
      sg0: sg-xxxxx