title: CloudFormation target group health checks are inconsistent
body: <p>I have an AWS CloudFormation template that creates an Application Load Balancer that routes traffic to a target group consisting of two instances running Apache.</p>
  <p>Sometimes when I create the stack both health checks are fine as shown below:
  <a href="https://i.stack.imgur.com/FMcIQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FMcIQ.png" alt="enter image description here" /></a></p>
  <p>But other times, when I create the stack <strong>using the exact same template</strong>, one or both of the health checks fail:
  <a href="https://i.stack.imgur.com/rIWbx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rIWbx.png" alt="enter image description here" /></a></p>
  <p>The portion of the template that creates the ALB and instances is:</p>
  <pre>    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
      DependsOn: 
        - Ec2InstanceA
        - Ec2InstanceB
      Properties:
        IpAddressType: ipv4
        Scheme: internet-facing
        SecurityGroups:
          - !Ref InstanceSecurityGroup
        Subnets:
          - !Ref PublicSubnetA
          - !Ref PublicSubnetB
        Tags:
          - Key: Name
            Value: !Sub ${AWS::StackName}-ALB
        Type: application
    Listener:
      Type: AWS::ElasticLoadBalancingV2::Listener
      Properties:
        DefaultActions:
          - Type: forward
            TargetGroupArn: !Ref MyTargetGroup
        LoadBalancerArn: !Ref MyApplicationLoadBalancer
        Port: '80'
        Protocol: HTTP
  
    MyTargetGroup:
      Type: AWS::ElasticLoadBalancingV2::TargetGroup
      Properties: 
        HealthCheckEnabled: true
        Port: 80
        Protocol: HTTP
        VpcId: !Ref VPC
        Targets: 
          - Id: !Ref Ec2InstanceA
          - Id: !Ref Ec2InstanceB
        TargetType: instance
    
    Ec2InstanceA:
      Type: AWS::EC2::Instance
      Properties:
        InstanceType: t2.micro
        ImageId: ami-0323c3dd2da7fb37d
        KeyName: KeyPair
        NetworkInterfaces:
          - AssociatePublicIpAddress: true
            DeviceIndex: 0
            GroupSet:
              - Ref: InstanceSecurityGroup
            SubnetId:
              Ref: PrivateSubnetA
        UserData:
          Fn::Base64:                                
            !Sub |
                #!/bin/bash -ex
                sudo yum install -y httpd;
                sudo echo &quot;&lt;html&gt;&lt;h1&gt;Hello CloudFormation A!!&lt;h1&gt;&lt;/html&gt;&quot; &gt; /var/www/html/index.html;
                cd /var/www/html;
                sudo chmod 755 index.html;
                sudo service httpd start;
                sudo chkconfig httpd on;
    Ec2InstanceB:
      Type: AWS::EC2::Instance
      Properties:
        InstanceType: t2.micro
        ImageId: ami-0323c3dd2da7fb37d
        KeyName: KeyPair
        NetworkInterfaces:
          - AssociatePublicIpAddress: true
            DeviceIndex: 0
            GroupSet:
              - Ref: InstanceSecurityGroup
            SubnetId:
              Ref: PrivateSubnetB
        UserData:
          Fn::Base64:                               
            !Sub |
                #!/bin/bash -ex
                sudo yum install -y httpd;
                sudo echo &quot;&lt;html&gt;&lt;h1&gt;Hello CloudFormation B!!&lt;h1&gt;&lt;/html&gt;&quot; &gt; /var/www/html/index.html;
                cd /var/www/html;
                sudo chmod 755 index.html;
                sudo service httpd start;
                sudo chkconfig httpd on;
  </pre>
  <p>I'm guessing it's some sort of resource timing issue, but I'm not really sure.</p>