{"cells":[{"cell_type":"markdown","id":"db807cc9","metadata":{"id":"db807cc9"},"source":["# Recitation 0.7: AWS Spring 2025 Introduction to Deep learning\n","\n","\n","## Tanghang Elvis Tata\n","## Peter Wauyo\n"]},{"cell_type":"markdown","id":"beebfbb2","metadata":{"id":"beebfbb2"},"source":["## Running an AWS instance"]},{"cell_type":"markdown","id":"f21b68c2","metadata":{"id":"f21b68c2"},"source":["Request a service quota increase"]},{"cell_type":"markdown","id":"a42e0968","metadata":{"id":"a42e0968"},"source":["Launch an instance AWS"]},{"cell_type":"markdown","source":["## Connecting to an AWS instance"],"metadata":{"id":"TbvBS96pzmfg"},"id":"TbvBS96pzmfg"},{"cell_type":"markdown","source":["1. **Move** the downloaded `.pem` file from a source folder to the `.ssh` folder\n","```\n","mv <source_file_path> ~/.ssh/\n","```\n","\n"," Explanation:\\\n","`<source_file_path>`: Replace this with the path to the downloaded `.pem` file you want to move.\\\n","`~/.ssh/`: This is the destination folder where SSH keys are typically stored. `~` represents your home directory.\n","\n"," Example\n"," ```\n"," mv ~/Downloads/my-key.pem ~/.ssh/\n"," ```"],"metadata":{"id":"li9V47UXYcGN"},"id":"li9V47UXYcGN"},{"cell_type":"markdown","id":"26691cc5","metadata":{"id":"26691cc5"},"source":["2. **Change** the `.pem` file permissions (To avoid this error: UNPROTECTED PRIVATE KEY FILE!)\n","\n"," ```\n","chmod 700 <key>\n","```\n","\n"," Example\n","```\n","chmod 700 ~/.ssh/my-key.pem\n","```\n"]},{"cell_type":"markdown","id":"74e32c52","metadata":{"id":"74e32c52"},"source":["3. **Connecting** to the instance:\n","```\n","ssh -i <key> <user>@<hostname>\n","```\n","Example\n","```\n","ssh -i ~/.ssh/my-key.pem ec2-user@ec2-192-168-1-2.compute-1.amazonaws.com\n","```\n"]},{"cell_type":"markdown","id":"21e931c3","metadata":{"id":"21e931c3"},"source":["4. **Sending** a file to the instance (optional)\n","```\n","scp -i <key> <local_path> <user>@<hostname>:<remote_path>\n","```"]},{"cell_type":"markdown","id":"b5bcc28e","metadata":{"id":"b5bcc28e"},"source":["5. **Downloading** a file to local (optional)\n","```\n","scp -i <key> <user>@<hostname>:<remote_path> <local_path>\n","```"]},{"cell_type":"markdown","id":"c9447e73","metadata":{"id":"c9447e73"},"source":["## Running a notebook on AWS"]},{"cell_type":"markdown","id":"b9548b88","metadata":{"id":"b9548b88"},"source":["1. On the server, start the Jupyter Notebook:\n","```\n","jupyter notebook --no-browser --port=8888\n","```\n","\n"," The server will show `http://localhost:8888/?token=<TOKEN>`.\n","\n"," Take note of the token."]},{"cell_type":"markdown","id":"044169f3","metadata":{"id":"044169f3"},"source":["2. Connect to the remote server port locally via SSH:\n","    \n"," ```bash\n","ssh -i <key> -L <local_port>:<remote_host>:<remote_port> <remote_user>@<remote_host>\n","```\n","Example \\\n","If you have a Jupyter Notebook running on the remote server (`<remote_host>`) on port 8888 (`<remote_port>`), run this command \\\n","`ssh -i <key> -L 8889:localhost:8888 <remote_user>@<remote_host>`"]},{"cell_type":"markdown","id":"b71b380c","metadata":{"id":"b71b380c"},"source":["3. On a local browser, open `localhost:8889`\n"," - For the token, paste it from the first step."]},{"cell_type":"markdown","source":["## Connect to an AWS instance using VS Code"],"metadata":{"id":"nJnC9xrBzuiI"},"id":"nJnC9xrBzuiI"},{"cell_type":"markdown","source":["\n","1. Install the Remote - SSH Extension\n"," *   Open VS Code and go to the Extensions view (`Ctrl+Shift+X` or `Cmd+Shift+X` on Mac)\n"," *   Search for and install the \"Remote - SSH\" extension."],"metadata":{"id":"WVBD0LNJzykk"},"id":"WVBD0LNJzykk"},{"cell_type":"markdown","source":["2. Open the Command Palette\n"," *   List item Open the Command Palette using `Ctrl+Shift+P` (or `Cmd+Shift+P` on Mac)."],"metadata":{"id":"G0Ev7lIZ28bb"},"id":"G0Ev7lIZ28bb"},{"cell_type":"markdown","source":["3. Use the `ssh` Command\n"," *   In the Command Palette, type and select: \\\n","\"Remote-SSH: Connect to Host\"\n"," *   In the text box that appears, type the SSH command for example: \\\n","`ssh -i <key> <user>@<PUBLIC_IP_OF_YOUR_INSTANCE>`"],"metadata":{"id":"vy0kT8x73wtV"},"id":"vy0kT8x73wtV"},{"cell_type":"markdown","source":["4. Establish the Connection\n"," *   Press `Enter`. VS Code will attempt to connect to the AWS instance.\n"," *   A new VS Code window will open if the connection is successful.\n","\n"],"metadata":{"id":"EVoYVBe95IpB"},"id":"EVoYVBe95IpB"},{"cell_type":"markdown","source":["5. Verify the Connection\n","\n"," *   Check the terminal in the new window to confirm you are logged in to the remote instance.\n"," *   The file system of the AWS instance should also be accessible in the `Explorer` tab.\n","\n"],"metadata":{"id":"cqiwGa_f5GXQ"},"id":"cqiwGa_f5GXQ"}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.5"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":5}