I have 2 EC2 instances within same VPC and same subnet, both have same security groups attached to them. But 1 instance has public ip that was allocated when launching the instance (lets say public-ip-instance). The other one only has private IP, but I created and attached an elastic ip(lets say elastic-ip-instance). So both instances now have public ip's.
But I can access the ec2 instance with public ip that was allocated during launch and not the instance with elastic ip. Both have same user data script. I'm just trying to access the instance through browser using the instance ip address.
I've tried searching everywhere and seems like there shouldn't be any difference in accessing an ec2 instance over elastic ip, but it doesn't seem to work. What is needed to have an instance access over elastic ip or am I doing something wrong.
CodePudding user response:
It appears your situation is:
- You launched an Amazon EC2 instance with a User Data script that installs a web server
- When the instance was launched, it was not assigned a Public IP address
- You later added an Elastic IP address
- You are unable to access content via HTTP on that server
When an EC2 instance in a public subnet does not have an IP address, it is unable to access the Internet. Therefore, when your User Data script ran and attempted to install the web server, it could not download the software from the Internet. Therefore, the web server was not installed on the instance.
You can correct this by logging into the instance and running the install script again. It will work this time since you have added an Elastic IP address.
Alternatively, terminate the instance and launch another instance, being sure to assign it a public IP address on launch.