I have 2 instances running and a web application in one of them (Say instance1) uses private IP of another instance (Say instance2) to call a service.
I restarted instance2(IP changes after restart) and restarted the web application on instance1 after adjusting the configurations accordingly, and application was up and running successfully. But then suddenly it stopped responding after 2 hours and when I looked for the problem, I found that the private IP of the instance2 was again changed while it was running.
Has it happened with anyone else? If yes what's the solution for this?
The private IP address of an Amazon EC2 instance will never change.
It will not change while an instance is running.
It will not change while an instance is stopped.
You cannot change a private IP address. (However, I think that if you assign multiple private IP addresses, you can add/remove the secondary addresses, but not the primary IP address.)
You cannot launch another instance with the same private IP address of another instance (in the same VPC), even if the other instance is stopped.
The above only applies to the private IP address, not the public IP address.