Monday, March 14, 2022

[SOLVED] Possible to associate Elastic IP to an instance without immediately losing public ip?

Issue

I have a windows EC2 instance running a production website and DNS is configured to have my domain name point to its public IP. There is currently no Elastic IP (EIP) associated with the instance. I would like to start using a Elastic IP and have my domain name point to it instead of the public IP (which can change if I ever have to change the instance).

Reading the documentation I find this statement troubling:

When you associate an EIP with an instance, the instance's current public IP address is released to the EC2-Classic public IP address pool.

My fear is this:

  • I assign an EIP to the instance and the public IP is released.
  • Now my website no longer works, because the domain name points to the public IP, which is no longer associated with my EC2 instance.
  • I must then point DNS records to the EIP. But this could take up to 48 hours for propagation to take place (i.e. my site may be be unreachable for up to 48 hours).

How can I do this without having to live through DNS propagation?


Solution

If your EC2 instance is in a VPC, you can add a second network interface onto your EC2 instance. You can associate your Elastic IP address with that second network interface. This way, your EC2 instance could respond to both IP addresses.

Instructions

  1. Create a new Network Interface in the same subnet as your EC2 instance.
  2. Allocate a new Elastic IP for your VPC (if you haven't done so already).
  3. Associate the Elastic IP address with your new Network Interface (eni).
  4. Attach your new Network Interface to your EC2 instance.

Do not change your DNS yet.

You may need to RDP/SSH into your EC2 instance to make some configuration changes to ensure your EC2 instance responds correctly to the new IP address.

Modify the hosts file on your local computer to test connecting to your website via the new IP address.

When that works, do the DNS switch and restore your hosts file.



Answered By - Matt Houser
Answer Checked By - Marie Seifert (WPSolving Admin)