Setting Up EC2 Instance
- Go to AWS Console
- Click EC2
- Click instance in the left side menu.
- Click Launch instance at the top right.
- Pick your server of choice, generally the first Ubuntu that appears in the list.
- Choose the default, usally free tier instance unless you have a reason to choose otherwise. Then click Next: Configure instance details at the bottom right.
- Leave configure instance details as default, click next until you arrive at configure security group.
- Add rules for SSH, HTTP and HTTPS to be accessed from source: Anywhere.
- Click next and then launch. It will prompt you to select or create a new key pair, create if you dont have one. Name it as you wish but keep the name simple. I will use: “exampleec2”. Click download key pair and put the .perm file somewhere safe.
- Once the key is donwloaded, click Launch at the bottom right. Then once launched click view instances.
- Click on the instance id then copy the Public IPv4 DNS address, or the IP, but generally the one that looks like a URL: ec2-3-83-212-13.compute-1.amazonaws.com.
** FOR WINDOWS USERS **
- Download and install putty from here: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
- Find puttygen in the start menu and open it.
- Click load, navitate to the folder with the .perm file in it, change the file types from .ppk to all and open the .perm file. Click save private key once it has loaded. Passphrase is better for security, but not always needed. Exit out, now a .ppk file has been created.
- Find putty in the start menu and open it.
- Insert the address, ec2-3-83-212-13.compute-1.amazonaws.com in the host name along with the SSH port number, 22, in the port number.
- Go to SSH in the category menu on the left, then go to auth, then where it says private key file for authenitcation and click browse and find the .ppk file that was saved.
- Go back to session and choose the save option to save this setting with a name created under saved sessions, ala exampleec2.
- Click open to access the terminal of your ec2 server. Click ‘yes’ at teh security alert and then type ‘ubuntu’ as the password, or whatever the default password for your server distro choice is.
The server is set up at this point, and you have access to what is effectively the command prompt.
Setting up Software on EC2 Instance
More often than not we will want the server to run whether we have SSH’d into the server or not. For this we will use tmux. There is a great cheatsheat of tmux commands here: https://tmuxcheatsheet.com/.
- Type ‘tmux new -s mysession’ into the terminal. shift + insert is your friend for copy-pasting into the terminal. You can change the name from ‘mysession’ to whatever you want.
- Type ‘sudo apt-get update’ to make sure the linux packages are up to date.
Whenever you want to access the session again, type ‘tmux a -t mysession’.
At this point you can start installing software just like you would from the command prompt on your own PC.
Setting up Jupyter Notebook/Lab on EC2 Instance
//This section is under construction.
- Type ‘sudo apt-get install build-essential cmake g++ gfortran git vim pkg-config python-dev software-properties-common wget’ and select yes at the prompt.
- Type ‘sudo apt install python3-pip’ and select yes at the prompt.
- pip3 install pandas numpy flask scikit-learn jupyter jupyterlab werkzeug
- nano ~/.bashrc
- export PATH=”$HOME/.local/bin:$PATH”Y
- jupyter notebook –generate-config
- cd to the directory and open with nano and then paste:
- c.NotebookApp.ip = ‘*’
- jupyter-lab –ip=0.0.0.0 –port=9999