What happens after you deregister an EC2 instance from Elastic Load Balancer?

Solution 1:

https://forums.aws.amazon.com/message.jspa?messageID=231571

We just ran a test of ELB both with health check and with manually removing an instance from the ELB, and all existing connections were dropped rudely almost immediately (within about a second).

Amazon's response:

We are aware of the pain that this behavior can cause our customers, and feedback like this helps us better understand the real impact and importance of the issue. Please keep it coming.

Don't count on a quick fix, this is still the case two years later.

Solution 2:

Because i recently used this feature myself, and there is solution to the problem asked/described (not covered in the existing comments/answers):

Its called Connection Draining and can be set in the ELB Configuration. You define a timeout (defaults to 300 seconds) that the ELB keeps the Connection open to finish, before dropping them.

Here is a Blog Post explaining how to set up Connection draining in your ELB: https://aws.amazon.com/de/blogs/aws/elb-connection-draining-remove-instances-from-service-with-care/

And the AWS Documentation: http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/config-conn-drain.html

Hm, i can not post more thant 2 links because i lack the reputation .... If you go on github.com and search in the awslabs account for aws-codedeploy-samples you will find shell scripts that unregister instances from ELBs.