Skip to content

Instantly share code, notes, and snippets.

@giantryansaul
Created December 14, 2015 05:35
Show Gist options
  • Save giantryansaul/dfb557d047572d96d68f to your computer and use it in GitHub Desktop.
Save giantryansaul/dfb557d047572d96d68f to your computer and use it in GitHub Desktop.
Run Jupyter from an amazon free tier AWS server

Installing Jupyter notebook to AWS

This is an early draft of this guide, which currently does not include any screenshots. I may be making a lot of assumptions about what you do or do not know in this guide and so I welcome any constructive criticism to help make it more useful. Please feel free to fork this guide and annotate it where it does not work, I would welcome any pull requests to improve this documentation.

Setup amazon linux server (free tier)

  • From Amazon's EC2 page, go to Launch Instance
  • Choose an Amazon Linux 64-bit server and continue
  • Select t2.micro (this is the free tier)
  • Continue to the Add Storage page and adjust this up to 30GB if you're so inclined (default is 8GB, which is plenty)
  • Tag your instance with a name like "notebook"
  • Create a security group for your instance including the following ports:
  • SSH
  • HTTPS
  • Custom: port 8888 on 0.0.0.0/0
  • Confirm the new instance

SSH into your new instance and install Anaconda

  • Setup credentials for logging in through ssh
  • Grab anaconda: https://www.continuum.io/downloads -> wget locally
  • bash downloaded anaconda file
  • follow steps for installation
  • add anaconda to PATH (this is an option in the installation of anaconda)

Aside: Why Anaconda and not pip?

I tried to make the pip installation of Jupyter work for some time without much luck. There were various kernal errors when trying out the final product and I just didn't know how to troubleshoot some of the problems that were coming up. It should be possible to install through pip, but Anaconda clearly installs more of the necessary dependencies, so I went forward with that. I do prefer pip and virtualenv to Anaconda, but only because of past experience with it.

Install Jupyter and setup notebook configuration

  • conda install jupyter
  • jupyter notebook --generate-config
  • cd .jupyter
  • configure settings file under .jupyter: (use vim or nano)
  • c.NotebookApp.ip = '*'
  • c.NotebookApp.open_browser = False
  • c.NotebookApp.port = 8888
  • test that Jupyter is running by trying jupyter notebook, you can access the notebook right now from your browser by navigating to https://{public IP}:8888
  • If you started Jupyter, exit by pressing Ctrl+C twice

Even though Jupyter is in a runnable state, I highly recommend setting up a basic password protection. Password protection isn't worth much, however, if you are not protecting that password through a secure transmission, so SSL is also required.

Setup security password

  • Run ipython from AWS
  • Run the following from the iPython terminal, changing "secret" to your desired password:
  • from IPython.lib import passwd
  • password = passwd("secret")
  • password
  • Copy the output password
  • Exit iPython -> exit()
  • Open the configuration file for Jupyter again in vim or nano
  • Set c.NotebookApp.password = '' to the copied password and save.

Setup SSL

  • From the home directory, run:
  • openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
  • Open the configuration file again.
  • Set c.NotebookApp.certfile = ’/home/ec2-user/mycert.pem' and save.

Create a folder for the notebook

An important note about Jupyter notebook is that it will host the directory that you start the server from. Therefore, if you run Jupyter from your home directory, it will include the Anaconda directory, the .jupyter directory and your certificate file! Create a new directory just for your new notes.

  • mkdir notebook

Run Jupyter from screen

Screen is a standard linux tool that allows you to have processes running in the background while you are away from the terminal.

  • Run screen
  • cd notebook
  • jupyter notebook
  • ctrl+a, then d, or in other words, hold the ctrl key with the A key, then hit the D key. This will exit screen.

If you want to get back to the terminal, run screen -rd

You can now access your notebook through https://{public IP}:8888. You will need to tell your browser to trust the certificate from the server, since it is an unregistered certificate. This is completely fine and your connection is still secure.

Next steps

That's it! But you may want to look into these extra credit things:

  • Setup an elastic IP address so that your public IP is always the same.
  • Setup a domain and route it to your elastic IP. Amazon offers this service through their Route 53 service in AWS, but you can use any domain registrar.
  • Setup other kernals to run in iPython, such as Python 2
  • Back up your notes through an EBS snapshot
@pingzh
Copy link

pingzh commented May 26, 2017

@jackgolding Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment