This is a tutorial on running Project Jupyter Notebook on an Amazon EC2 instance.
Note: This is not a tutorial for beginners. In fact, it's for myself. I don’t explain some of the steps fully and don’t explain some concepts. There are other tutorials out there for that explain each and every step in details.
Create an AWS account
An EC2 instance requires an AWS account. You can make an account here.
Navigate to EC2
Visit the EC2 Management console and click on "Launch Instance" button.
Next, you must choose an AMI (Amazon Machine Image) which defines the Operating System for your instance, as well as any configurations and pre-installed software.
Click on AWS Marketplace, and search for Deep Learning AMI with Source Code (CUDA 8, Ubuntu). Once you find the appropriate AMI, click on the "Select" button.
This AMI contains all the environment files and drivers for you to train on a GPU. It has cuDNN, and many the other packages.
Select the Instance Type
Next, you must choose an instance type, which is the hardware on which the AMI will run.
Filter the instance list to only show “GPU compute”:
Select the p2.xlarge instance type:
Note: This particular instance type would require you to request AWS to increase your GPU limits.
Now finally, click on the "Review and Launch" button:
Configure the Security Group
Running and accessing Jupyter notebooks from AWS requires special configurations.
By default, AWS restricts access to most ports on an EC2 instance. In order to access the Jupyter notebooks, you must configure the AWS Security Group to allow access to port 8888.
Click on "Edit security groups".
On the "Configure Security Group" page:
Select "Create a new security group".
Set the "Security group name" (i.e. "Jupyter").
Click "Add Rule".
Set a "Custom TCP Rule":
- Set the "Port Range" to "8888".
- Select "Anywhere" as the "Source".
Click "Review and Launch" (again).
Launch the Instance
Click on the “Launch” button to launch your GPU instance.
Create an Authentication Key Pair:
AWS will ask if you’d like to specify an authentication key pair. Select “Create a new key pair” and click the "Download Key Pair" button. This will download a .pem file, which you'll need to be able to access your instance.
After the .pem file has been downloaded, click the “Launch Instances” button.
Click the “View Instances” button to go to the EC2 Management Console and watch your instance boot.
From this point on, AWS will charge you for running this EC2 instance. You can find the details on the EC2 On-Demand Pricing page.
Login to the Instance
After launch, your instance may take a few minutes to initialize.
From a terminal, navigate to the location where you stored your .pem file.
Set permissions on key pair
chmod 400 YourKeyName.pem in Terminal.
Connect using SSH
ssh -i YourKeyName.pem ubuntu@X.X.X.X, where X.X.X.X is the IPv4 Public IP of the Instance.
Configure Jupyter notebook settings
In your instance, in order to create a config file for your Jupyter notebook settings, type:
jupyter notebook --generate-config.
Then, to change the IP address config setting for notebooks, type:
sed -ie "s/#c.NotebookApp.ip = 'localhost'/#c.NotebookApp.ip = '*'/g" ~/.jupyter/jupyter_notebook_config.py
Test the Instance
Make sure everything is working properly by verifying that the instance can run a Keras notebook.
On the EC2 instance
Clone a GitHub repository
Enter the repo directory:
Install the requirements:
sudo python3 -m pip install -r requirements/requirements-gpu.txt
Start Jupyter notebook:
jupyter notebook --ip=0.0.0.0 --no-browser
From your Local machine
- On your instance terminal, there will be the following line: "Copy/paste this URL into your browser when you connect for the first time, to login with a token:." Copy everything starting with the
- Access the Jupyter notebook index from your web browser by visiting:
X.X.X.X:8888/?token=...(where X.X.X.X is the IP address of your EC2 instance and everything starting with :8888/?token= is what you just copied).
- Click on any Jupter notebook to run.