☁ AWS Cloud Engineer JourneyBeginner → Cloud Practitioner → Solutions Architect

Day 5Compute · Lab⏱ 2h

EC2: Your First Server

By the end of today you can Launch a Linux server in the cloud, connect to it with SSH, serve a web page from it, and terminate it safely. You already did this locally in your nginx-lab. Now you'll do it on the internet.

1. First principles: a server is just a computer you can reach

EC2 (Elastic Compute Cloud) rents you a virtual computer. Under the hood, AWS slices a powerful physical machine into many isolated virtual machines. You choose:

ChoiceQuestion it answersAnalogy
AMIWhat OS/software is pre-installed?A move-in-ready template: furnished or empty flat
Instance typeHow much CPU/RAM?Flat size: studio vs 4-bedroom
Key pairHow do I prove I'm allowed in?The physical key (the .pem file)
Security groupWhich network traffic is allowed in/out?The doorman's guest list
Storage (EBS)Where is my disk?The wardrobe
User dataWhat runs automatically on first boot?Cleaners who set up the flat before you arrive

Instance type names decode like t3.micro: family t (burstable general purpose), generation 3, size micro. Others: m general, c compute, r memory, i storage, g/p GPU.

You 🌍 Security group22 SSH ← my IP80 HTTP ← anyoneall else: blocked EC2 instance (t3.micro) Amazon Linuxnginx :80EBS volume (8 GB disk)
Traffic must pass the security group before it reaches your instance.

2. Lab: deploy your nginx page on the internet

Cost safetyChoose a free-tier eligible instance type (the console labels it), launch one instance, and terminate it at the end of today's session.
  1. EC2 → Launch instance. Name: day5-web. AMI: Amazon Linux 2023. Type: free-tier eligible (t3.micro or t2.micro).
  2. Key pair: create new (RSA, .pem), download. Then in your Linux terminal: chmod 400 ~/Downloads/day5.pem. Move it to ~/.ssh/. Never into Git.
  3. Network settings → Edit: new security group allowing SSH from "My IP" (not 0.0.0.0/0!) and HTTP from anywhere.
  4. Advanced → IAM instance profile: pick ec2-s3-read-role from Day 3.
  5. Advanced → User data (runs once on first boot as root):
    #!/bin/bash
    dnf install -y nginx
    echo "<h1>Cloud Engineering Lab 02</h1><p>Hello from EC2 in $(hostname)</p>" > /usr/share/nginx/html/index.html
    systemctl enable --now nginx
  6. Launch. When "running", copy the Public IPv4 address and open http://THAT-IP in your browser (use http, not https). Wait ~1 minute if it doesn't load.
  7. SSH in from your terminal:
    ssh -i ~/.ssh/day5.pem ec2-user@PUBLIC_IP
    systemctl status nginx      # same commands you used in nginx-lab
    curl -s localhost
    sudo tail /var/log/nginx/access.log   # you'll see your own visit!
    exit
  8. Experiment (learn by breaking): edit the security group and remove the HTTP rule. Reload the page. It hangs (a blocked port causes a timeout, not an error). Add it back.
  9. Cleanup: select the instance → Instance state → Terminate. Verify it shows "terminated". Delete the security group if you wish.
📸 Evidence: browser showing your page + the EC2 console: evidence/day05-ec2-web.png. Also copy your user-data script into aws-course/labs/day05-user-data.sh in Git.

3. Lifecycle you must know

StateCompute billed?Disk billed?
RunningYesYes
StoppedNoYes (EBS)
TerminatedNoNo (root volume deleted by default)

Public IPs change on stop/start. An Elastic IP keeps one fixed (and is billed if unattached/unused, as public IPv4 addresses are charged).

4. Exam notes

Remember

5. Quiz

Q1. Your website times out after you launch it. Most likely cause?The security group doesn't allow inbound HTTP (port 80).
Q2. What does "stateful" mean for a security group?If inbound traffic is allowed, the reply is automatically allowed out (and vice versa).
Q3. Which pays no compute charge but still costs for storage?A stopped instance (its EBS volume remains).
Q4. How should an instance get permission to read S3?Attach an IAM role via an instance profile.

6. Checklist