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.

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:

  1. Select "Create a new security group".

  2. Set the "Security group name" (i.e. "Jupyter").

  3. Click "Add Rule".

  4. Set a "Custom TCP Rule":

    1. Set the "Port Range" to "8888".
    2. Select "Anywhere" as the "Source".
  5. 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.

Be Careful!

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

Type chmod 400 YourKeyName.pem in Terminal.

Connect using SSH

Type 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/

Test the Instance

Make sure everything is working properly by verifying that the instance can run a Keras notebook.

On the EC2 instance

  1. Clone a GitHub repository

  2. Enter the repo directory: cd repo-files/

  3. Install the requirements:
    sudo python3 -m pip install -r requirements/requirements-gpu.txt

  4. Start Jupyter notebook: jupyter notebook --ip= --no-browser

From your Local machine

  1. 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 :8888/?token=.
  2. 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).
  3. Click on any Jupter notebook to run.

Copy & Share: