CLF-C02 Beginner 20 min

Launch Your First EC2 Instance

Launch, connect to, and configure an Amazon EC2 instance. Understand AMIs, instance types, security groups, and user data.

Amazon EC2VPCSecurity Groups
Progress: 0 / 6 steps
Step 1
Open EC2 Console

1. Sign into AWS Console (console.aws.amazon.com)
2. Search "EC2" in top bar → click EC2
3. Click "Launch Instance" (orange button)

Note your region in the top-right corner.

Tip: Bookmark: https://console.aws.amazon.com/ec2/
Step 2
Configure Instance

1. Name: MyFirstEC2
2. AMI: Amazon Linux 2023 (Free Tier eligible)
3. Instance type: t2.micro (Free Tier)
4. Key pair: Create new key pair → "my-key-pair" → RSA → .pem → Download
5. Keep other defaults

Tip: Download and SAVE the .pem file. You cannot download it again after this step!
Step 3
Configure Security Group

1. Network settings → Edit
2. Add rule: Type=SSH, Source=My IP
3. Add rule: Type=HTTP, Source=Anywhere (0.0.0.0/0)
4. Launch Instance

Tip: "My IP" for SSH is more secure than opening to the world (0.0.0.0/0).
Step 4
Connect via EC2 Instance Connect

1. Wait: State=Running, Status checks=2/2 passed
2. Select instance → Connect
3. EC2 Instance Connect tab → Connect
4. A terminal opens in your browser!

bash
# Test commands once connected:
whoami
uname -r
curl http://169.254.169.254/latest/meta-data/instance-id
Tip: Instance metadata at 169.254.169.254 is only accessible from within the instance.
Step 5
Install Apache Web Server

Run these commands to install and start a web server:

bash
sudo dnf update -y
sudo dnf install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
echo "<h1>Hello from AWS! Instance: $INSTANCE_ID</h1>" | sudo tee /var/www/html/index.html
Tip: Copy the Public IPv4 from EC2 console and paste into a new browser tab to see your webpage!
Step 6
Clean Up

IMPORTANT: Terminate instance to avoid charges!
1. Select instance → Actions → Instance State → Terminate
2. Confirm termination
3. Also release any Elastic IPs you allocated

Tip: Stopped EC2 instances still incur EBS storage charges. Terminate (not stop) to fully clean up.