Connect to Jupyter Notebook Running on EC2 Instance

Connect to Jupyter Notebook Running on EC2 Instance

Last updated:
Table of Contents

If you need to handle data that's too large for your machine, one alternative is to spin up an AWS EC2 instance (for example, the AWS Deep Learning AMI) and do your work on that machine via jupyter notebook.

The simplest way to do it is to start up a jupyter notebook on the remote server and then set up an SSH tunnel from your machine to the remote server, so that you can use that as if it were on your local machine.

Here are the steps to get you started.

1) SSH to instance

Replace user-name and remote-hostname with your username and hostname

(my-machine)$ ssh -i my-private-key.pem user-name@remote-hostname

2) Setup Password for Jupyter

On the remote machine do:

Just do jupyter notebook password and chosse a password:

(ec2-instance)$ jupyter notebook password
Enter password: 
Verify password: 
[NotebookPasswordApp] Wrote hashed password to /home/ubuntu/.jupyter/jupyter_notebook_config.json

3) Start Jupyter notebook

On the remote machine do:

use nohup at the beginning and & at the end to stop the server from being killed if you log out

(ec2-instance)$ nohup jupyter notebook --no-browser --port=8888
nohup: ignoring input and appending output to 'nohup.out'

4) Create SSH Tunnel Connection

On your local machine do:

This example uses key-based authentication (the -i flag). You should point to the private key you chose when you initaliazed the EC2 instance.

(my-machine)$ ssh -i my-private-key.pem -N -f -L localhost:8888:localhost:8888 user-name@remote-hostname

5) Open up the URL on the browser

If you used the example line above to set up the tunnel, you need to open your browser at http://localhost:8888.

jupyter notebook Enter the password your set previously on step 2

After inserting the password, you should be able to use Jupyter:

jupyter-notebook-remote Great Success!


References