Launch Your First EC2 Instance
Launch, connect to, and configure an Amazon EC2 instance. Understand AMIs, instance types, security groups, and user data.
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.
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
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
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!
# Test commands once connected:
whoami
uname -r
curl http://169.254.169.254/latest/meta-data/instance-id
Run these commands to install and start a web server:
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
IMPORTANT: Terminate instance to avoid charges!
1. Select instance → Actions → Instance State → Terminate
2. Confirm termination
3. Also release any Elastic IPs you allocated