Connecting Jupyter to EC2
How I use an EC2 instance for Deep Learning
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
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!