2

I am hosting a web app in Amazon Elastic Beanstalk (EB). The web app is written in php. EB also uses Elastic Load Balancer (ELB). The web app implements a websocket with the client. Here is what I have done so far:

  1. I know I have to listen to the private ip, not 127.0.0.1 of the instance for this to work
  2. implemented a listener in load balancer to connect to the instance port
  3. opened inbound and outbound traffic for the port in security groups.

If the EB deployment goes for horizontal scaling (increase the number of instances), will the private ips of the scaled instances remain same (please explain)? If not, and I believe so, how do I get the private ip address of the current instance that is serving the client?

So far its working perfectly without any problem, but there's only one instance running. I tried listing the clients and I can get the private ips with the list but I don't know how to identify the instance that is currently serving the file.

Please help me.

4
  • EBS doesn't have an IP. It's mounted into your virtual machine just like a physical device. So your question doesn't make any sense. Commented Apr 15, 2015 at 19:28
  • @Jordan yes linux and apache ami Commented Apr 15, 2015 at 19:30
  • @Machavity ebs doesn't have ip, but for websocket to work one should listen to the private ip of the ec2 instance that is serving the client through ebs. Commented Apr 15, 2015 at 19:32
  • Question wasn't about EBS, it was about Elastic Beanstalk. Edited to clarify. Commented Apr 15, 2015 at 21:12

1 Answer 1

1

This will do the trick:

<?php $ip = shell_exec('hostname -i'); ?> 

important: this works only for the linux environment. For windows, hostname -i is not valid. You can refer to https://superuser.com/questions/382265/ for further ideas.

Sign up to request clarification or add additional context in comments.

1 Comment

On my lightsail account this returned 127.0.0.1. But the uppercase version -I did work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.