EC2 and JupyterLab Setup Instructions from PODAAC Coding Club #1 and #2
*Contributors: Jack McNeils, Cedric David
The following steps are specific for JPL Cloud. It is usually simplier with a less stringent cybersecurity measure.
Create EC2 Instance
- https://goto.jpl.nasa.gov/awsconsole a. Log in with JPL credentials b. Supply your JPL RSA token (same for VPN): PIN + Token d. Ensure the region shown at the top right is “US West (Oregon) us-west-2”
- Go to EC2 / AMI Catalog / My AMIs(12)
- De-select “Owned by me”
- Select one of the JPL-based EXTERNAL instances; click “Launch Instance with AMI”.
- Name and tags: pick a name
- Key pair (login): Create new key pair (keep all default: Create new key pair, RSA, .pem) Download the file as “KeyPair.pem”
- Click Launch instance
- Click on instance and capture the “Private IPv4 addresses xxx.xxx.xx.xx”
- Got to Mac Terminal:
chmod 400 KeyPair.pem
ssh -i KeyPair.pem jpluser@xxx.xxx.xx.xx
- Don’t forget to go to “Instance State” and select “Terminate Instance” when you’re done.
Setup JupyterLab (Single-User)
- Start an ec2 instance following the instructions above.
- Connect to the instance via ssh.
Remember to set the following parameters appropriately:
-i
points the ssh client on your local machine at your pem key to authenticate-L
tunnels traffic on port9889
between the ec2 instance and your local machine
ssh -i "KeyPair.pem" jpluser@ec2-x-x-x-x.us-west-2.compute.amazonaws.com -L 9889:localhost:9889
OR, perhaps a different user if running an AMI that's not managed by JPL, e.g. ec2-user
for the Amazon Linux AMI:
ssh -i "KeyPair.pem" ec2-user@ec2-x-x-x-x.us-west-2.compute.amazonaws.com -L 9889:localhost:9889
- Update packages. Optionally install wget, git, screen etc.
sudo yum update -y && sudo yum install wget git screen -y
- Download miniconda install script into tmp/ and execute it with bash. Then, activate the base environment.
mkdir -p tmp
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O tmp/miniconda.sh && \
bash tmp/miniconda.sh -b -p $HOME/conda && \
source ~/conda/bin/activate
- Create a new environment called jupyter running Python 3.7; activate it; install JupyterLab and other required packages.
conda create -n jupyter python=3.7 -y && \
conda activate jupyter && \
conda install -c conda-forge requests tqdm numpy pandas matplotlib netCDF4 xarray jupyterlab -y
- Start jupyterlab server in a screen.
Start a new screen session called ipylab:
screen -S ipylab
Use Python to generate and store a hashed password as a shell variable:
PW="$(python3 -c 'from notebook.auth import passwd; import getpass; print(passwd(getpass.getpass(), algorithm="sha256"))')"
Start jupyter lab instance with the following parameters:
jupyter lab \
--port=9889 \
--ip='127.0.0.1' \
--NotebookApp.token='' \
--NotebookApp.password="$PW" \
--notebook-dir="$HOME" \
--no-browser \
&
Detach the screen by pressing CTRL + A -> D.
Optionally, append the following line to your .bash_profile
in order to print the running jupyter servers upon ssh login:
printf '\n~/conda/envs/jupyter/bin/jupyter server list && echo\n\n' >> .bash_profile
- Access the server through your web browser: http://127.0.0.1:9889/