Search code examples
amazon-web-servicesamazon-ec2elastic-load-balanceraws-cloudformation

Set static private IP addresses to AWS EC2 Instances registered with an AWS Elastic Load Balancer


I am attempting to set static private IP addresses to AWS EC2 Instances registered with an AWS Elastic Load Balancer.

The most popular approach I encountered so far has been with the use of Auto Scaling Groups. This approach has been well elaborated in this forum discussion.

Later, I came across AWS Auto Recovery for Amazon EC2 Instances feature which simplifies much of the work related to the attachment of AWS Elastic Network Interfaces discussed in the above mentioned forum discussion (auto scaling approach).

But an unclear portion of the auto recovery based approach to me (a would be problem), is its success in dynamically registering recovered EC2 Instances during failure, with any load balancers they have been registered with. No information on how auto recovered instances can be used and work with load balancers were found. This introduction to auto recovery feature has defined the following benefits of auto recovery feature:

  • The running instance is automatically transferred to the new underlying hardware.
  • There is no need of migration to a new EC2 instance.
  • The instance-id does not get changed.
  • The IP address, if it is an Elastic IP address remain same.
  • The instance metadata and the private IP addresses also remain same.

The above benefits have given me the impression that auto recovered instances would successfully work with any load balancers (primarily due to constant instance ID) they are attached to during failure and recovery.

But my questions are as follows:

  1. Does auto recovery feature of EC2 instances successfully work with any load balancers they are attached to (in terms of successful instance registration and deregistration during failure and recovery)?
  2. Which is the best approach for setting static private IP addresses to AWS EC2 Instances registered with AWS Elastic Load Balancers?

Solution

  • Does auto recovery feature of EC2 instances successfully work with any load balancers they are attached to (in terms of successful instance registration and deregistration during failure and recovery)?

    Yes, it works, because there is no registration/deregistration that occurs. The instance remains registered. The point of instance auto-recovery is that no other components in EC2 realize that the instance has been replaced. Everything about the instance remains exactly as it was -- instance ID, private IP address, EBS and ENI attachments -- after instance recovery.

    A recovered instance is identical to the original instance, including the instance ID, private IP addresses, Elastic IP addresses, and all instance metadata.

    http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-recover.html

    In other words, it's exactly the same instance in every way that matters... only the physical hardware powering it is different.

    The balancer will conclude the instance is unhealthy when it fails, but will not realize it has gone away and been replaced by auto recovery, so the balancer will continue to health-check the instance the whole time... and when the health checks start succeeding after the instance recovers, the balancer starts sending traffic to the instance again.

    Which is the best approach for setting static private IP addresses to AWS EC2 Instances registered with AWS Elastic Load Balancers?

    You don't need to do this. Balancers are associated with instances, not IP addresses. If you terminate an instance and create a new instance with the same private IP, none of the balancers that previously sent traffic to that private IP will continue to do so, because the balancers know that their intended target -- a specific instance with a specific instance ID -- is gone.

    Of course, you can use static IPs with instances if they're not in auto-scaling groups, but there is no reason to do so related to the issue at hand.