Manage a Floating IP on AWS Services

4.1k views Asked by At

Let's pretend I have an AWS EIP allocated as: eipalloc-94eb5af1 Let's pretent I have an AWS Network Interface: eni-e3d20a9a, eni-e3d20a9a

Let's now pretent I have two EC2 servers. The network interfaces are on those two servers.

Now...let's suppose I wanted to setup monitoring. Ping monitoring perhaps. If eni-e3d20a9a becomes invisible, I wish to transfer the EIP to eni-e3d20a9a.

This can be easily accomplished by:

aws ec2 associate-address --allocation-id eipalloc-03d3b666 \
    --allow-reassociation --network-interface-id eni-98e03bd3

Also, setup of a rudimentary bash script on each server to monitor each other is rather simple.

But, I need advice on doing this efficiently on AWS. Not with a script Perhaps with Lambda or Cloudwatch?

What is the best way to accomplish the EIP move?

2

There are 2 answers

1
John Rotenstein On BEST ANSWER

You are correct that you can monitor an instance and, in case of failure, re-associate an Elastic IP Address to a different instance or network interface.

There is no automatic facility to performing this monitoring/switching for you. You could monitor your instance from a script on an EC2 instance, from a scheduled AWS Lambda function or even from a computer anywhere on the Internet. However, you would be responsible for that script.

Alternatively, you could have the instances themselves send a custom metric to Amazon CloudWatch on a regular basis and then create an alarm that will trigger if the metric value changes (eg has not updated lately, indicating a potential system failure). The alarm could trigger an AWS Lambda function that would re-associate the Elastic IP address.

Or, another idea is to use Amazon Route 53 with a Health Check. If the Amazon Route 53 health checkers detect a problem, they can change the resolution of a DNS name to an alternate IP address. This is not re-associating an Elastic IP address. Rather, it is changing the IP address returned when a DNS name is resolved.

0
Singaravelan On

If I understand your problem right, you have to switch the EIP if one instance which acts as a primary goes down to a second instance, and now this secondary/backup instance will act as a primary.

If my above understanding is right, you can use keepalived to automatically monitor and switch elastic IP between instances

This link have example how to do the same https://www.peternijssen.nl/high-availability-haproxy-keepalived-aws/