Intro

The goal of this is to run a jupyter notebook as if it were locally but have all of it running in the backend. I have tried sagemaker and other packaged products, and I prefer just using Jupyter-lab. This guide is how I connect.

This is mostly a reference guide to refer back to until you memorize the steps. If this is your first time using AWS, EC2, or you aren't already fairly familiar with the process then I recommend checking out a guide that explains things a bit more. This is meant to be be a good place to use as a reminder of what to do while you do it the first 10 or 20 times, rather than a step-by-step guide on how to do it.

A great place (and what I used initially) for getting instructions to do this for the first time would be: https://fzr72725.github.io/2018/01/14/How-to-Connect-to-Jupyter-Notebook-Server-on-AWS-EC2-from-Your-Local-Machine.html

Launch an EC2 Instance

First, launch an EC2 instance. I use p2.xlarge for almost everything. You will be prompted to create or use an existing key pair. You will need this private key, so download it and store it somewhere. If you lose it, you lose the EC2 instance. I have a copy of mine in S3

Connect to your EC2 Instance

In the AWS console, you can click connect. If your EC2 instance isn't started then start it. It will give you instructions for SSHing in. There's 2 steps that are important here.

chmod 400 <key.pem>

and

ssh -i "key.pem" username@whatever_it_tells_you_in_aws_console.compute-1.amazonaws.com

Launch Jupyter

In the EC2 I just ssh into I run

jupyter-lab --no-browser --port=8889

I stored my key in the directory ~/.aws, but that should be replaced with wherever. I open a new console and run

ssh -i ~/.aws/key.pem  -L 8000:localhost:8889 username@whatever_it_tells_you_in_aws_console.compute-1.amazonaws.com

From there open localhost:8000 in your browser and you are good to go. If it asks for a token you can find it in the terminal output where you ran jupyter-lab!