|
| 1 | +--- |
| 2 | +title: "Deploy Your First Instance" |
| 3 | +sidebar_label: "5. Hands-on Lab" |
| 4 | +sidebar_position: 5 |
| 5 | +description: "A step-by-step guide to launching, securing, and connecting to your first AWS EC2 Linux server. Learn the essential commands to prepare your server for a MERN stack deployment and understand the best practices for managing your cloud resources." |
| 6 | +--- |
| 7 | + |
| 8 | +Welcome to the final capstone of the **CodeHarborHub** AWS Beginner series! Today, you will move from theory to practice by launching a live **Ubuntu Linux** server in the AWS Cloud. |
| 9 | + |
| 10 | +:::info Why This Matters |
| 11 | +Deploying your own server is a critical milestone in your DevOps journey. It gives you hands-on experience with cloud infrastructure, security, and server management. This lab will prepare you for real-world scenarios where you'll need to deploy and manage applications in the cloud. |
| 12 | +::: |
| 13 | + |
| 14 | +## The Deployment Lifecycle |
| 15 | + |
| 16 | +Before we click the buttons, let's look at what happens behind the scenes when you request a server. |
| 17 | + |
| 18 | +```mermaid |
| 19 | +sequenceDiagram |
| 20 | + participant U as You (Developer) |
| 21 | + participant C as AWS Console |
| 22 | + participant R as EC2 Resource |
| 23 | + participant N as VPC/Network |
| 24 | +
|
| 25 | + U->>C: Select AMI & Instance Type |
| 26 | + C->>R: Provision Virtual Hardware |
| 27 | + R->>N: Attach Elastic Network Interface |
| 28 | + N->>R: Assign Public IP |
| 29 | + R->>R: Status Check (Initialising) |
| 30 | + R-->>U: Instance Running ✅ |
| 31 | +``` |
| 32 | + |
| 33 | +In this lifecycle: |
| 34 | +1. You select the **AMI** (Amazon Machine Image) and **Instance Type** (virtual hardware). |
| 35 | +2. AWS provisions the virtual server and attaches it to the network. |
| 36 | +3. The server undergoes status checks to ensure it's healthy before you can connect. |
| 37 | + |
| 38 | +## Step-by-Step Implementation |
| 39 | + |
| 40 | +Follow these steps carefully. At **CodeHarborHub**, we use the **Free Tier** to ensure you learn without incurring costs. |
| 41 | + |
| 42 | +### 1. Launch the Instance |
| 43 | + |
| 44 | +1. Log in to the [AWS Management Console](https://aws.amazon.com/console/). |
| 45 | +2. In the search bar, type **EC2** and select it. |
| 46 | +3. Click the orange **"Launch instance"** button. |
| 47 | + |
| 48 | +### 2. Name and Application Image (AMI) |
| 49 | + |
| 50 | + * **Name:** `CodeHarborHub-Web-Server` |
| 51 | + * **AMI:** Select **Ubuntu** (Choose the `Ubuntu Server 24.04 LTS` - Free tier eligible). |
| 52 | + |
| 53 | +### 3. Instance Type & Key Pair |
| 54 | + |
| 55 | + * **Instance Type:** Select `t2.micro` (1 vCPU, 1 GiB Memory). |
| 56 | + * **Key pair:** Click **"Create new key pair"**. |
| 57 | + * **Name:** `codeharbor-key` |
| 58 | + * **Format:** `.pem` (for OpenSSH/Mac/Linux) or `.ppk` (for PuTTY/Windows). |
| 59 | + * **Action:** Download and save this file safely! **You cannot download it again.** |
| 60 | + |
| 61 | +### 4. Network Settings (Security Groups) |
| 62 | + |
| 63 | +The Security Group acts as a virtual firewall. |
| 64 | + |
| 65 | +* **Allow SSH traffic from:** Anywhere (0.0.0.0/0) — *For production, use "My IP".* |
| 66 | +* **Allow HTTPS traffic** (Port 443). |
| 67 | +* **Allow HTTP traffic** (Port 80). |
| 68 | +* **Review and Launch** your instance. |
| 69 | + |
| 70 | +## Connecting to Your Server |
| 71 | + |
| 72 | +Once the instance state says **"Running"**, it's time to log in via your terminal. |
| 73 | + |
| 74 | +<Tabs> |
| 75 | +<TabItem value="linux-mac" label="Linux / macOS" default> |
| 76 | + |
| 77 | +1. Open your terminal and navigate to the folder containing your `.pem` file. |
| 78 | +2. Set permissions (Security requirement): |
| 79 | + ```bash |
| 80 | + chmod 400 codeharbor-key.pem |
| 81 | + ``` |
| 82 | +3. Connect using the Public IP: |
| 83 | + ```bash |
| 84 | + ssh -i "codeharbor-key.pem" ubuntu@<YOUR_PUBLIC_IP> |
| 85 | + ``` |
| 86 | + |
| 87 | +</TabItem> |
| 88 | +<TabItem value="windows" label="Windows (PowerShell)"> |
| 89 | + |
| 90 | +1. Open PowerShell as Administrator. |
| 91 | +2. Navigate to your key folder and run: |
| 92 | + ```powershell |
| 93 | + ssh -i .\codeharbor-key.pem ubuntu@<YOUR_PUBLIC_IP> |
| 94 | + ``` |
| 95 | + |
| 96 | + *(Note: Modern Windows 10/11 has OpenSSH built-in\!)* |
| 97 | + |
| 98 | +</TabItem> |
| 99 | +</Tabs> |
| 100 | + |
| 101 | +## Industrial Level Commands |
| 102 | + |
| 103 | +Once you are inside your server, run these commands to prepare it for a **MERN Stack** deployment: |
| 104 | + |
| 105 | +```bash |
| 106 | +# Update the package manager |
| 107 | +sudo apt update && sudo apt upgrade -y |
| 108 | + |
| 109 | +# Install Node.js (Current LTS) |
| 110 | +curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - |
| 111 | +sudo apt-get install -y nodejs |
| 112 | + |
| 113 | +# Verify installation |
| 114 | +node -v |
| 115 | +``` |
| 116 | + |
| 117 | +:::info Best Practice |
| 118 | + |
| 119 | +Always keep your server updated to patch security vulnerabilities. Use `sudo apt update && sudo apt upgrade -y` regularly to maintain a secure environment. |
| 120 | + |
| 121 | +::: |
| 122 | + |
| 123 | + |
| 124 | +## The "Wallet Safety" Rule |
| 125 | + |
| 126 | +To keep your AWS account free, you must manage your resources. At the end of your practice session: |
| 127 | + |
| 128 | +1. Go to the **Instances** dashboard. |
| 129 | +2. Select your instance. |
| 130 | +3. Click **Instance state** -> **Terminate instance**. |
| 131 | + |
| 132 | +:::danger Warning |
| 133 | +**Stopping** an instance saves the data but might still charge for EBS storage. **Terminating** deletes the instance and stops all billing for that resource. |
| 134 | +::: |
| 135 | + |
| 136 | +## Graduation Challenge |
| 137 | + |
| 138 | +Now that your server is running, try to install **Nginx** (`sudo apt install nginx`) and paste your instance's **Public IP** into a browser. If you see the "Welcome to nginx!" page, you have successfully deployed a web server to the cloud! |
0 commit comments