Connect to Ray Dashboard in EC2 Instance

Hey everyone! I am new and using Ray in AWS. Recently, I set up the Ray cluster using an EC2 instance. All works very well however, I have a problem showing the Ray Dashboard in the browser. I am running ray dashboard config.yml. in EC2 and then I connect to the instance using ssh -L 8265:localhost:8265 user@server_public_ip but cannot see anything in the browser. I even tried the same code to connect the head node, but still facing the same issue. I wonder if there is anyone who had the experience before to help with it.

BTW, when I try to connect to the head node facing the following error:

bind [127.0.0.1]:8265: Permission denied ray dashboard

Not sure If it is required to modify the instance security group or not?!

cc: @sangcho may know more about it

Hmm I think you are supposed to run ray dashboard [config yaml] in your local machine. And then you should be able to access it from localhost:8265

Thank you @sangcho for the response - I will try it out and would report the here

@beh_ray did you successfully connect to the Ray Dashboard in EC2 instance?

@sangcho and @Huaiwei_Sun is there a detailed procedure on how to get this done?

https://docs.ray.io/en/latest/cluster/configure-manage-dashboard.html#dashboard-in-browser

Basically:

  • make sure the dashboard is running on your remote ec2 machine
  • port forward to your local port and view it in the browser
1 Like

@Huaiwei_Sun I noticed that VSCode is able to port forward whenever I used my ec2’s local python3.8 with ray to initialize a new context, but I dont get the automatic port forwarding when I used the anaconda virtual environment provided by the ec2 instance’s AMI image. Whats the explicit port forwarding from each python virtual environment terminal?

I don’t think it’s a ray question… That’s a generic port forward question.

Answer from GPT 4 for your reference:


Port forwarding from an EC2 instance to your local machine is typically done through an SSH tunnel. This is useful when you want to securely access a service running on the EC2 instance from your local machine. Here's a basic guide to set this up:

Prerequisites:

Ensure you have SSH access to your EC2 instance. You should have the EC2 instance's public IP address and the private key file (.pem file) used for SSH access.
Install an SSH client on your local machine. Most Unix-based systems (like macOS and Linux) have SSH installed by default. Windows users can use PuTTY or the built-in SSH client in PowerShell or Windows Subsystem for Linux (WSL).
Open an SSH Tunnel:

Open a terminal (or command prompt/PowerShell in Windows).

Use the following command to create an SSH tunnel:

css
Copy code
ssh -i /path/to/your-key.pem -L [local_port]:localhost:[remote_port] ec2-user@[ec2-public-ip]
Replace /path/to/your-key.pem with the path to your private key file. Replace [local_port] with the port number on your local machine that you want to use for the tunnel. Replace [remote_port] with the port number on your EC2 instance that you want to access. Replace [ec2-public-ip] with the public IP address of your EC2 instance.

For example, if you want to access a web server running on port 8080 on your EC2 instance and make it accessible on port 9090 on your local machine, the command would be:

vbnet
Copy code
ssh -i /path/to/your-key.pem -L 9090:localhost:8080 ec2-user@[ec2-public-ip]
Access the Service:

With the tunnel established, you can now access the service running on the EC2 instance by using localhost:[local_port] on your local machine. In the previous example, you would use localhost:9090 to access the web server.
Keep the Tunnel Open:

Keep the terminal window open for as long as you need the tunnel. Closing it will close the SSH tunnel.
Security Considerations:

Be mindful of the security implications of port forwarding. Ensure that only authorized users can access the SSH tunnel.
If you're opening a port that should not be publicly accessible, consider binding it to 127.0.0.1 on the EC2 instance to prevent external access.
Remember that the username (ec2-user in the example) might be different depending on the AMI used by your EC2 instance. For example, it's ubuntu for Ubuntu AMIs. Always check your instance's documentation for the correct username.

@Huaiwei_Sun thanks for your response. I agree that the port forwarding code you posted works and is not specific to ray dashboard. My curiosity was more to know if there was some options in the /python/path/to/ray/dashboard.py that allows the port forwarding because without the -L option, ssh via VSCode does automatic port forwarding for local ec2-user Python but not for virtual environment python… Sticking to what works. thanks

I don’t know. Not familiar with this actually. Maybe someone else knows what you are curious about