title: Stop traffic to unhealthy instances without replacing them by auto scaling
body: <p>Using <strong>ELB</strong> for TCP protocol and <strong>AWS Auto Scaling</strong> I run into the following problem when scaling out.</p>
  
  <ul>
  <li>three EC2 instances each with 2,000 connections</li>
  <li>scaling out because that is my specified threshold</li>
  <li>a new instance gets added by Auto Scaling</li>
  </ul>
  
  <p>How can I stop now traffic going to the three EC2 instances which have too many connections?</p>
  
  <ol>
  <li><p>Removing it from ELB will mean that it will get terminated after a maximum of 1h using connection draining. <strong>Bad: TCP connections will get closed.</strong></p></li>
  <li><p>Marking the EC2 instance as unhealthy using CloudWatch. <strong>Bad: Auto Scaling will detect and replace unhealthy instances</strong></p></li>
  <li><p>Detaching EC2 instance from Auto Scaling group manually via AWS CLI. 
  <strong>Bad: Detaching it from Auto Scaling will also remove it from ELB, see 1.</strong></p></li>
  </ol>
  
  <p>The only possible solution I can see here and I am not sure if it is feasible:</p>
  
  <p>Using CloudWatch mark the EC2 instance as unhealthy. ELB will stop distributing traffic to it. At the same time update the EC2 health for Auto Scaling manually:</p>
  
  <pre><code>aws autoscaling set-instance-health --instance-id i-123abc45d –-health-status healthy
  </code></pre>
  
  <p>This should override the health in a way that ELB will continue to ignore the EC2 instance and AWS Auto Scaling will not try to replace the instance. Would that work or is there a better solution?</p>