Launch Jupyterlab on AWS EC2 and Publish to Kyso


This is a short guide to setting up and running a Jupyterlab environment on an Amazon EC2 instance. We have recently made a cool new Jupyterlab extension that allows anyone to publish their Jupyter notebooks directly to the web as awesome data blogs from anywhere.

1. Create an AWS Account and Sign into AWS.


If you don't already have an aws account, go to and sign up. This only takes a few minutes. Once logged in, navigate to the EC2 Dashboard from the console.

Loading output library...

2. Create an Instance

Loading output library...

On the EC2 Dashboard, click Launch Instance. Select your Amazon Machine Image (AMI). An Ubuntu image will create a typical Linux-based server. Under Choose your Instance Type select Free Tier instance t2 micro (should be automatically pre-selected). Micro instances are eligible for a free usage tier. For the first 12 months following your AWS sign-up date, you get up to 750 hours of micro instances each month.

If you wish, you can add tags and configure the instance details before launching.

3. Configure Security Group Settings


Navigate to Configure Security Group Settings, the final step before launching your instance. Don't worry if you forget to do this step before launching the instance - you can adjust the security settings even after the instance is up and runnning. A security group is a collection of firewall rules that restrict the network traffic for the instance. Here we are setting the inbound rules for when we are connecting to the server via SSH & then also when we launch our Jupyterlab environment.

Below, I'm allowing inbound traffic from my local IP address on port 22 and authorizing access to the instance using HTTP (or HTTPS) for when I launch Jupyterlab.

Loading output library...

Click Review and Launch on the bottom-right. You are now on the final Step - if happy with our configuration, click 'Launch'.

4. Launch your Instance


This will create a pop-up window where you've to create a Key Pair. A key pair consists of a public key that AWS stores, and a private key file that you store. Together, they allow you to connect to your instance securely. Create a key pair and make sure to save it somewhere safe on download. You won’t be able to replace it. In the box below Key pair name, fill in a key pair name. I named my key Kyso_Guide, but you can name it whatever you like. Click on Download Key Pair. This will download the key. Keep it somewhere safe. You won't be able to replace it. Click Launch Instances.

Loading output library...

The instance is now launched. Navigate back to the Amazon EC2 console. Wait until the Instance State is running before proceeding to the next step.

5. Connect to Linux Instance using SSH


Now that your instance is launched and you've configured the security settings, you need to connect to it. On the console click Connect to launch a small window with a guide on how to connect to your Linux Instance using SSH.

Make sure your key (pem file) matches your key pair name. Open an SSH client (terminal on a mac). Locate your private key file (in this case, Kyso_Guide.pem). Your key must not be publicly viewable for SSH to work, so execute the following command in the same directory as the key:

chmod 400 Kyso_Guide.pem

Connect to the instance using its Public DNS. This is viewable on the EC2 Dashboard, under instances. The window at the bottom provides the description of your selected instance at the top. On the right-hand side you'll see the Public DNS. Answer yes to the prompt upon running the following line:

ssh -i Kyso_Guide.pem

Loading output library...

Awesome! You're officially connected to the remote server.

6. Set up and run your Jupyterlab Environment


First, we'll set up our data science environment by downloading the Anaconda distribution to the instance from the Anaconda installer archive. Visit the archive to download the latest version of the Linux 64-bit version. Run:

Install and execute the build:


source .bashrc

If the installer doesn't give you the option to prepend the Anaconda3 install location to PATH in your /home/ubuntu/.bashrc or if you answer no by mistake you can manually set it with:

export PATH=/home/ubuntu/anaconda3/bin:$PATH

Make a separate folder for our notebooks and cd into that directory:

mkdir notebooks

cd notebooks

Fire up Jupyterlab:

jupyter lab

7. SSH into your Jupyterlab Environment


From the client, SSH to the Jupyterlab environment:

ssh -i Kyso_Guide.pem -L 8000:localhost:8888

i identifies an alternate identification file to use for public key authentication. For this guide, the key is in our current directory anyway.

L specifies that the given port on the local host is to be forwarded to the given host and port on the remote side (AWS instance). This means that whatever is running on the second port number (i.e. 8888) on AWS will appear on the first port number (i.e. 8000) on your local computer. The localhost port should be the port at which the Jupyterlab environment is running. You can also configure the port on the instance.

In your browser go to localhost:8000 and enter the token. And that's it! You've offically set up a Jupyterlab environment on a EC2 instance!

8. Install Kyso's Publish Extension


The next step is to download Kyso's very own Jupyterlab extension. You can take a look at our documentation on Github here. The prerequisites are Jupyterlab 0.34 (or later) and a Kyso account.

You can check your Jupyterlab version by running:

jupyter lab --version

To install the extension, run the following.

For Jupyter Lab 0.35:

jupyter labextension install @kyso/jupyterlab

For Jupyter Lab 0.34:

jupyter labextension install @kyso/jupyterlab@jupyterlab-0.34.9

Note that this install requires node 5 or later. If you encounter any issues such as ValueError: Please install nodejs 5+ and npm before continuing installation when installing the above run the following & then install the extension:

curl -sL | sudo -E bash -

sudo apt-get install nodejs -y

Once installed, refresh the page & you will see the Kyso option in the top navbar. You are now able to publish awesome data blogs directly to Kyso from an AWS EC2 instance!

Loading output library...