This guide shows the steps to set up Jupyter on AWS and set it up so that it starts automatically when an instance in launched or re-started. I have tested these steps with the Ubuntu 16.04 LTS AMI ami-b7a114d7 that AWS offers.

AMI setup

Start a brand new Ubuntu 16.04 LTS AMI. When launching an AMI, use the following custom security groups:

  • Type: Custom TCP Rule
    • Protocol: TCP
    • Port Range: 8888
    • Source: Custom
  • Type: SSH
    • Protocol: TCP
    • Port Range: 22
    • Source: Custom

Jupyter setup

After ssh-ing into the machine ran the following commands:

sudo apt-get update
wget #update with the latest one from

Follow the installation steps then:

source .bashrc
jupyter notebook --generate-config
key=$(python -c "from notebook.auth import passwd; print(passwd())")

Type in a password and continue

cd ~/.ssh
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.key -out mycert.pem

Press Enter several times leaving all the fields blank. Then

cd ~
sed -i "1 a\
c.NotebookApp.ip = ''\\
c.NotebookApp.open_browser = False\\
c.NotebookApp.password = u'$key'" .jupyter/
jupyter notebook

I observed that by having all the lines in .jupyter/ commented out except for the three lines above, I am able to access the Jupyter notebook even behind a firewall.

Set Jupyter to start when instance boots

Add the following line right before the exit 0 line in \etc\rc.local

su ubuntu -c 'bash /home/ubuntu/'

and create the file /home/ubuntu/ with the following lines

export PATH="$PATH:/home/ubuntu/anaconda2/bin"
jupyter notebook --notebook-dir=/home/ubuntu/ --profile=nbserver > /tmp/ipynb.out 2>&1 &

The --notebook-dir= indicates the location to launch the jupyter notebook.