1

I have deployed an Angular app and a Java REST-API on my ec2-instance.

My angular app is hitting the Java REST-API if I use a public IP, but when I provide a private IP of my instance, it throws an connection time out error.

So is there any way I can call my Java REST-API using private IP from within my Angular app. I have setup a vpc and the instance is lying inside the vpc.

Thomas Gotwig
  • 3,659
  • 3
  • 17
  • 15
  • Are both part on the same Amazon EC2 instance? If so, it would be better to use `localhost`, so that the request does not even need to leave the instance. (It also sounds like an issue with your Security Group, so please edit your question and show the security group configuration if you are not going to use `localhost`.) – John Rotenstein Jun 09 '20 at 01:04
  • I can use localhost but it doesn't fullfil my purpose of accessing my api through private IP. I have allowed all traffic through Network ACL and in security group inbounds I have allowed access to all ports that my apps are using using from my IP as well as ec2 instance public IP. – Anand Tiwari Jun 09 '20 at 03:19
  • Then you should also configure the Security Group to allow Inbound on those ports from the Private IP address, too. Are both portions running on the same instance? – John Rotenstein Jun 09 '20 at 03:30
  • Yes, both are running on same instance. I will try by adding entry for private ip in security group inbound. – Anand Tiwari Jun 09 '20 at 05:03
  • Neither using localhost nor setting private ip in inbounds works. I think there is no way to use private ip for rest api as I am accessing it from node app which is internet facing. – Anand Tiwari Jun 10 '20 at 04:03

1 Answers1

0

Well as frontend code gets downloaded and runs on the client browser then the request for the backend resource will originate from the client IP and as we all know that we cannot connect to the internet from private IP that is why the request is failing when I try to use private IP.