I have a application stack that is deployed with cloud formation. It contains two auto scaling groups and one EC2 instance on its own.

How do I configure the EC2 instance or cloud formation to deploy to the IP address of of the old instance?

Out current solution is to issue the update-stack command twice. Once with the private IP of the the EC2 instance to something random withign the same subnet and then again with the original IP address.

Is there a better solution to achieve this?


Why does it need to keep the IP? For incoming traffic it's better to rely on DNS names rather than on any particular IPs (e.g. managed in Route53 with Cloud Formation). Or if you have the IP whitelisted in some Security Groups you can use the Source SG instead of IP. Very rarely a service needs to retain its IP for genuine reasons.

Anyway one solution I have deployed in the past for a custom DNS stack (one of the few services that refer to IPs and not domain names) was creating a separate Elastic Network Interface (ENI) with the required IP address and pass that around as instances were starting and stopping in the AutoScaling Group. It was done through the EC2 instance start-up script where the instance would detach the interface from the old instance and attach it to itself, essentially stealing the ENI from the old instance in the ASG.

It was a dirty hack but it worked. However if at all possible design your deployment in such a way that it doesn't depend on any particular IPs. Or provide more details why it is needed.

Hope that helps :)

  • The IP needs to remain the same because that is what the DNS is pointed to. This is the company's internal DNS server. Updates to which have to go through service requests ie. massive downtime.
    – charsi
    May 5 '20 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.