20
votes

I'm running Ubuntu 14.04 LTS on an AWS EC2 instance. I'm trying to connect to Jypter in Safari from my MacBookPro. I opened https port 443 and TCP 8888 in my security group.

ubuntu@ip-10-0-1-62:~$ netstat -a  | grep 8888
tcp        0      0 localhost:8888          *:*                     LISTEN     
tcp        0      0 localhost:8888          localhost:36190         TIME_WAIT  
ubuntu@ip-10-0-1-62:~$ netstat -a  | grep 443
unix  3      [ ]         STREAM     CONNECTED     12443    
ubuntu@ip-10-0-1-62:~$ 

I can't connect to Jupyter from my Safari browser on my Mac. (I can connect to Tensorboard on port 6006).

ubuntu@ip-10-0-1-62:~$ jupyter notebook
[W 20:40:14.909 NotebookApp] Unrecognized JSON config file version, assuming version 1
[I 20:40:14.921 NotebookApp] Writing notebook server cookie secret to /run/user/1000/jupyter/notebook_cookie_secret
[I 20:40:15.224 NotebookApp] JupyterLab alpha preview extension loaded from /home/ubuntu/anaconda/lib/python2.7/site-packages/jupyterlab
[I 20:40:15.230 NotebookApp] Serving notebooks from local directory: /home/ubuntu
[I 20:40:15.230 NotebookApp] 0 active kernels 
[I 20:40:15.230 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=c08a71a48c6e159bdbdcc95837c4e2e053349382c681899b
[I 20:40:15.231 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 20:40:15.232 NotebookApp] 

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=c08a71a48c6e159bdbdcc95837c4e2e053349382c681899b

enter image description here

$ telnet 52.8.16.250 8888
Trying 52.8.16.250...
telnet: connect to address 52.8.16.250: Connection refused
telnet: Unable to connect to remote host
$ telnet 52.8.16.250 6006
Trying 52.8.16.250...
telnet: connect to address 52.8.16.250: Connection refused
telnet: Unable to connect to remote host
$ telnet 52.8.16.250 8080
Trying 52.8.16.250...
telnet: connect to address 52.8.16.250: Connection refused
telnet: Unable to connect to remote host
$ telnet ec2-52-8-16-250.us-west-1.compute.amazonaws.com 8888
Trying 52.8.16.250...
telnet: connect to address 52.8.16.250: Connection refused
telnet: Unable to connect to remote host
$ telnet ec2-52-8-16-250.us-west-1.compute.amazonaws.com 20
Trying 52.8.16.250...

telnet: connect to address 52.8.16.250: Operation timed out
telnet: Unable to connect to remote host
5
Did you find a solution? Also having trouble with this. I have opened ports 443 and 8888 in the ec2 console but I'm still having trouble myself.Wolf Rendall

5 Answers

18
votes

Okay, found the issue:

Edit your jupyter configuration:

jupyter notebook --generate-config

vim /home/ubuntu/.jupyter/jupyter_notebook_config.py

Make sure that

c.NotebookApp.ip = '*'

Also make sure you opened the relevant security group in your EC2 server (for example port 8888)

Run Jupyter:

jupyter notebook

Now you can access it remotely with the right port

11
votes

For me ssh tunneling works great for such cases.

ssh -i /path/to/your/AWS/key/file -NL 8157:localhost:8888 user@host

where user and host depend on your ec2 instance.

After that you can browse to http://localhost:8157/

4
votes

Make sure your AWS instance security group configured as below screenshot: aws instance inbound security group configured

If you are sure that AWS is configured correctly for permissions, check if your network is not blocking the outbound traffic. You could try to do port tunneling when SSHing into your instance by doing:

ssh -i -L 8888:127.0.0.1:8888

then you can access jupyter locally by going to localhost:8888 on your browser

4
votes

enter image description here

I was getting above error but tried command: jupyter notebook --ip=*

This worked for me.

1
votes

Here is a full workflow end to end to run a Jupyter notebook or Jupyterlab on an Amazon AWS EC2 instance. (Expanding on @alexopoulos7's answer)

  • Launch an AWS EC2 instance, e.g. T2 micro for testing with free tier.
  • Increase storage size of system disk from 8GB to say 20GB to have some more space to install packages.
  • Just use the default security group. No need to add anything here! Default should be: inbound SSH, port 22, source 0.0.0.0/0, outbound all traffic, all ports)
  • Select your default key pair or create a new one (.pem file).
  • Save the key file to your local home directory, e.g. ~/ec2.pem. Set proper file permissions with chmod 400 ~/ec2.pem.

enter image description here

  • Get the public IPv4 address of your instance (wait until instance is actually running).
  • SSH to your instance with ssh -i ec2.pem ec2-user@< PUBLIC IPv4 ADDRESS OF YOUR INSTANCE >. If the IP address is for example 18.1.10.199 then the command is ssh -i ec2.pem [email protected]
  • Install miniconda with wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh, then bash Miniconda3-latest-Linux-x86_64.sh. Confirm all default choices when prompted. Confirm with yes, when asked if you wish the installer to initialize Miniconda.
  • exit and ssh again into your instance for changes to take effect.
  • Create a conda environment with conda create -n myenv python=3.8.
  • Activate environment with conda activate myenv.
  • Install jupyter/jupyterlab with conda install jupyter notebook jupyterlab
  • Start jupyter/lab with e.g. jupyter lab --no-browser
  • On your local machine set up an ssh tunnel to your EC2 instance with ssh -i ec2.pem -NL 9999:localhost:8888 [email protected]. The arguments: -i sets the key file, -N just forwards ports without executing a remote command and -L sets the connection from your local port – in our example 9999 – to the remote host/port.
  • Using a different port from the default 8888 locally has the advantage that you simultaneously can use jupyter notebook locally and remote.
  • Open a browser window on your local machine, punch in localhost:9999 as URL and login with the token that you see in the remote shell when you start jupyter. You should be good to go... 👍

PS: Don't forget to terminate your instance after you're done.