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?
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.
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 useaws 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.