

# Setting up a Jupyter Notebook server on a DLAMI instance
<a name="setup-jupyter"></a>

With a Jupyter Notebook server, you can create and run Jupyter notebooks from your DLAMI instance. With Jupyter notebooks, you can conduct machine learning (ML) experiments for training and inference while using the AWS infrastructure and accessing packages built into the DLAMI. For more information about Jupyter notebooks, see [The Jupyter Notebook](https://jupyter-notebook.readthedocs.io/en/latest/notebook.html) on the Jupyter User Documentation website.

To set up a Jupyter Notebook server, you must:
+ Configure the Jupyter Notebook server on your DLAMI instance.
+ Configure your client to connect to the Jupyter Notebook server. We provide configuration instructions for Windows, macOS, and Linux clients.
+ Test the setup by logging in to the Jupyter Notebook server.

To complete these steps, follow the instructions in the following topics. After you've set up a Jupyter Notebook server, you can run the example notebook tutorials that ship in the DLAMIs. For more information, see [Running Jupyter Notebook Tutorials](tutorial-jupyter.md).

**Topics**
+ [Securing server](setup-jupyter-secure.md)
+ [Starting server](setup-jupyter-start-server.md)
+ [Connecting client](setup-jupyter-connect.md)
+ [Logging in](setup-jupyter-login.md)

# Securing the Jupyter Notebook server on a DLAMI instance
<a name="setup-jupyter-secure"></a>

To keep your Jupyter Notebook server secure, we recommend setting up a password and creating an SSL certificate for the server. To configure a password and SSL, first [connect to your DLAMI instance](setup-connect.md), and then follow these instructions.

**To secure the Jupyter Notebook server**

1. Jupyter provides a password utility. Run the following command and enter your preferred password at the prompt.

   ```
   $ jupyter notebook password
   ```

   The output will look something like this:

   ```
   Enter password:
   					Verify password:
   					[NotebookPasswordApp] Wrote hashed password to /home/ubuntu/.jupyter/jupyter_notebook_config.json
   ```

1. Create a self-signed SSL certificate. Follow the prompts to fill out your locality as you see fit. You must enter `.` if you wish to leave a prompt blank. Your answers will not impact the functionality of the certificate.

   ```
   $ cd ~
   					$ mkdir ssl
   					$ cd ssl
   					$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem
   ```

**Note**  
You might be interested in creating a regular SSL certificate that is third-party signed and does not cause the browser to give you a security warning. This process is much more involved. For more information, see [Securing a notebook server](https://jupyter-notebook.readthedocs.io/en/6.2.0/public_server.html#securing-a-notebook-server) in the Jupyter Notebook user documentation.

**Next step**  
[Starting the Jupyter Notebook server on a DLAMI instance](setup-jupyter-start-server.md)

# Starting the Jupyter Notebook server on a DLAMI instance
<a name="setup-jupyter-start-server"></a>

After you [secure your Jupyter Notebook server with a password and SSL](setup-jupyter-secure.md), you can start the server. Log in to your DLAMI instance and run the following command that uses the SSL certificate that you created previously.

```
$ jupyter notebook --certfile=~/ssl/mycert.pem --keyfile ~/ssl/mykey.key
```

With the server started, you can now connect to it via an SSH tunnel from your client computer. When the server runs, you will see some output from Jupyter confirming that the server is running. At this point, ignore the callout that you can access the server via a local host URL, because that won't work until you create the tunnel.

**Note**  
Jupyter will handle switching environments for you when you switch frameworks using the Jupyter web interface. For more information, see [Switching Environments with Jupyter](tutorial-jupyter.md#tutorial-jupyter-switching).

**Next step**  
[Connecting a client to the Jupyter Notebook server on a DLAMI instance](setup-jupyter-connect.md)

# Connecting a client to the Jupyter Notebook server on a DLAMI instance
<a name="setup-jupyter-connect"></a>

After you [start the Jupyter Notebook server on your DLAMI instance](setup-jupyter-start-server.md), configure your Windows, macOS, or Linux client to connect to the server. When you connect, you can create and access Jupyter notebooks on the server in your workspace and run your deep learning code on the server.

## Prerequisites
<a name="setup-jupyter-connect-prereqs"></a>

Be sure you have the following, which you need to set up an SSH tunnel:
+ The public DNS name of your Amazon EC2 instance. For more information, see [Amazon EC2 instance hostname types](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-naming.html) in the *Amazon EC2 User Guide*.
+ The key pair for the private key file. For more information about accessing your key pair, see [Amazon EC2 key pairs and Amazon EC2 instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html) in the *Amazon EC2 User Guide*.

## Connect from a Windows, macOS, or Linux client
<a name="setup-jupyter-connect-client"></a>

To connect to your DLAMI instance from a Windows, macOS, or Linux client, follow the instructions for your client's operating system.

------
#### [ Windows ]

**To connect to your DLAMI instance from a Windows client using SSH**

1. Use an SSH client for Windows, such as PuTTY. For instructions, see [Connect to your Linux instance using PuTTY](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-linux-inst-from-windows.html) in the *Amazon EC2 User Guide*. For other SSH connection options, see [Connect to your Linux instance using SSH](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-to-linux-instance.html).

1. (Optional) Create an SSH tunnel to a running Jupyter server. Install Git Bash on your Windows client, and then follow the connection instructions for macOS and Linux clients.

------
#### [ macOS or Linux ]

**To connect to your DLAMI instance from a macOS or Linux client using SSH**

1. Open a terminal.

1. Run the following command to forward all requests on local port 8888 to port 8888 on your remote Amazon EC2 instance. Update the command by replacing the location of your key to access the Amazon EC2 instance and the public DNS name of your Amazon EC2 instance. Note, for an Amazon Linux AMI, the user name is `ec2-user` instead of `ubuntu`.

   ```
   $ ssh -i ~/mykeypair.pem -N -f -L 8888:localhost:8888 ubuntu@ec2-###-##-##-###.compute-1.amazonaws.com
   ```

   This command opens a tunnel between your client and the remote Amazon EC2 instance that is running the Jupyter Notebook server.

------

**Next step**  
[Logging in to the Jupyter Notebook server on a DLAMI instance](setup-jupyter-login.md)

# Logging in to the Jupyter Notebook server on a DLAMI instance
<a name="setup-jupyter-login"></a>

After you [connect your client to the Jupyter Notebook server on your DLAMI instance](setup-jupyter-connect.md), you can log in to the server.

**To log in to the server in your browser**

1. In the address bar of your browser, enter the following URL, or click on this link: [https://localhost:8888](https://localhost:8888)

1. With a self-signed SSL certificate, your browser will warn you and prompt you to avoid continuing to visit the website.  
![\[SSL warning\]](http://docs.aws.amazon.com/dlami/latest/devguide/images/ssl-warning1.png)

   Since you set this up yourself, it is safe to continue. Depending your browser you will get an "advanced", "show details", or similar button.  
![\[SSL warning confirmation\]](http://docs.aws.amazon.com/dlami/latest/devguide/images/ssl-warning2.png)

   Click on this, then click on the "proceed to localhost" link. If the connection is successful, you see the Jupyter Notebook server webpage. At this point, you will be asked for the password you previously set up.

   Now you have access to the Jupyter Notebook server that is running on the DLAMI instance. You can create new notebooks or run the provided [Tutorials](tutorials.md).