Running Jupyter Notebook locally works fine for small datasets. But when your data does not fit in your laptop's RAM, or you need a GPU for model training, moving to an AWS EC2 instance is the natural next step. This walkthrough covers the setup from scratch.
Step 1: Launch an EC2 Instance
Log into the AWS console and navigate to EC2. Launch a new instance with Ubuntu Server as the AMI. For most data work, a t3.medium or t3.large is a reasonable starting point. If you need GPU support for deep learning, choose a p3.2xlarge (NVIDIA V100) or the more cost-effective g4dn.xlarge (T4).
During setup, create or select a key pair — you will need the .pem file to SSH in. In the security group settings, add an inbound rule: Custom TCP, port 8888, source 0.0.0.0/0. This is the default Jupyter port.
Step 2: Connect and Install Dependencies
SSH into your instance:
chmod 400 your-key.pem
ssh -i your-key.pem ubuntu@your-ec2-public-ip
Update the system and install Python and pip:
sudo apt update && sudo apt upgrade -y
sudo apt install python3-pip python3-dev -y
Install Jupyter and any libraries you need:
pip3 install jupyter pandas numpy scikit-learn matplotlib
Step 3: Configure Jupyter for Remote Access
Generate the Jupyter config file:
jupyter notebook --generate-config
Set a password so the notebook is not open to anyone with the IP:
jupyter notebook password
Open the config file:
nano ~/.jupyter/jupyter_notebook_config.py
Add or uncomment these lines:
c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.port = 8888
c.NotebookApp.open_browser = False
Setting ip to 0.0.0.0 tells Jupyter to listen on all network interfaces, not just localhost.
Step 4: Start Jupyter
jupyter notebook
Open a browser on your local machine and navigate to:
http://your-ec2-public-ip:8888
Enter the password you set and you are in.
Step 5: Keep it Running with tmux
If you close your SSH connection, the Jupyter process dies. Use tmux to keep it running in the background:
sudo apt install tmux -y
tmux new -s jupyter
jupyter notebook
# Press Ctrl+B then D to detach
To reattach later: tmux attach -t jupyter
Cost tip
EC2 instances charge by the hour even when idle. Stop the instance from the AWS console when you are done working. Your EBS volume (and its data) persists even when the instance is stopped — you only pay the storage cost, not the compute cost. Set up a billing alarm in CloudWatch to avoid surprise charges.