I have connection draining enabled for a ELB. According to the documentation at http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/TerminologyandKeyConcepts.html#conn-drain, a deregistering or unhealthy instance will keep existing connections open:

Connection draining causes the ELB load balancer to stop sending new requests to a deregistering instance or an unhealthy instance, while keeping the existing connections open.

I'd like to perform some maintenance on EC2 nodes in the ELB. It would be nice to gracefully take them out of rotation manually. I have tried failing the health checks and manually removing the EC2 instance from the ELB. Both of these actions kill existing connections to the instance.

How can I manually set a EC2 instance to deregistering or unhealthy state so that it will continue to serve existing connections but not accept new ones?

  • 2
    Manually removing it via the ELB console counts as deregistering per the docs. You may want to contact support if it isn't working right.
    – ceejayoz
    Sep 26, 2014 at 15:08

3 Answers 3


You could perhaps set up a new security group which rejects inbound connections from the ELB but allows outbound connections back.

When you need to perform maintenance, you can switch the affected EC2 instance to this new security group and wait for the remaining connections to drop off.

The only thing I'm not sure on is if changing the security group will kill existing connections. I don't believe it will but I haven't tested to be sure.

  • This is an interesting idea. I'll try this and will be happy to accept if it works.
    – Andy Shinn
    Sep 26, 2014 at 17:32
  • Hi Andy, am interested to know if that works? =)
    – ngzhongcai
    Mar 20, 2015 at 1:53

Connection draining only applies at network level, ELB doesn't know your session state. Please see this old answer. Is ELB draining tcp based?


If your instances are in an auto scaling group, you have the option to put them in maintenance with aws autoscaling enter-standby and to get them out of maintenance mode, you use aws autoscaling exit-standby. This will trigger the loadbalancer to drain connections.

If they are not in an auto scaling group, you will have to deregister and register them again. If you want to have a good example on how to do this, you can have a look at the CodeDeploy example here: https://github.com/aws-samples/aws-codedeploy-samples . This code will automatically put the instance in maintenance mode if it is in an auto scaling group and if not, it will remove the instance from the ELB and at the end of the update, add it again to all the target groups.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.