title: ELB backend connection errors when deregister ec2 instances
body: <p>I've written a custom release script to manage releases for an EC2 autoscaling application. The processing works like so...</p>
  
  <ol>
  <li>Create an AMI based on an application git tag.</li>
  <li>Create launch config.</li>
  <li>Configure ASG to use new launch config.</li>
  <li>Find current desired capacity for ASG.</li>
  <li>Set desired capacity to 2x previous capacity.</li>
  <li>Wait for new instances to become healthy by querying ELB.</li>
  <li>Set desired capacity back to previous value.</li>
  </ol>
  
  <p>This all works fairly well, except whenever I run this, the monitoring for the ELB is showing a lot of backend connection errors.</p>
  
  <p>I don't know why this would be occurring, as it should (based on my understanding) still service current connections if the "Connection draining" option is enabled for the ELB (which it is).</p>
  
  <p>I thought perhaps the ASG was terminating the instances before the connections could finish, so I changed my script to first deregister the instances from the ELB, and then wait a while before changing the desired capacity at the ASG. This however didn't make any difference. As soon as the instances were deregistered from the ELB (even though they're still running and healthy) the backend connection errors occur.</p>
  
  <p>It seems as though it's ignoring the connection draining option and simply dropping connections as soon as the instance has been deregistered.</p>
  
  <p>This is the command I'm using to deregister the instances...</p>
  
  <pre><code>aws elb deregister-instances-from-load-balancer --load-balancer-name $elb_name --instances $old_instances
  </code></pre>
  
  <p>Is there some preferred method to gracefully remove the instances from the ELB before removing them from the ASG?</p>