Move EC2 Instance out from Public Subnet to Private Subnet without losing private IP

0

Hi, We have a requirement where we want to move our DB instance out of existing Public Subnet to Private Subnet (we will create a new). The problem is we want to keep same private IP. I think it will not possible as new subnet will have obviously different IP range than existing subnet. However if it can be done please let me know. As it is DB instance we can't have too much downtime, so please let me know the correct process if want to transfer even with different Private IP.

已提问 9 个月前556 查看次数
2 回答
1

Hello.

If the subnets are different, the IP address will change, as you recognize.
If the IP address absolutely cannot be changed, it can be handled by removing routes destined for the Internet Gateway from the route table of the currently activated subnet and changing it to a private subnet.
However, this method is not recommended if EC2 other than the DB instance is running on the same subnet, as the impact may be significant.
If you are moving subnets, you can create a snapshot of EC2, create an AMI from the snapshot, and then create EC2 from the AMI.
In the case of this method, moving is easy, but it would be necessary to stop applications and other services because data updated during the move will not be saved.
Another method is to use a DMS.
This method should result in less data loss than restoring and moving from AMI.
Note, however, that you will need to configure the DMS and that there is a cost for something called a replication instance.
https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html

If you can provide some downtime to move subnets, I would recommend restoring from AMI.

profile picture
专家
已回答 9 个月前
  • Thanks for the reply, we can not move routes as well as you correctly mentioned there are other EC2 instances in that subnet. Looks like best way is, we have to compromise on the sticking on the same IP Address and get a new one. Thanks.

0

To avoid such issues, try to not to use IPs when comes to databases/EC2s. Not sure how many code changes are required, at this stage, but you can consider creating a R53 private hosted zone. Update your code to use the R53 record. When you export/import your DB to the new instance just update the R53 to point to the new IP.

Nikitas
已回答 9 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则