Overview
Amazon EC2 (Elastic Compute Cloud) is the backbone of AWS compute. This guide walks through everything you need to launch a production-grade EC2 instance — from choosing the right AMI to hardening SSH and attaching IAM roles.
Prerequisites
- AWS account with IAM admin access
- AWS CLI installed and configured (
aws configure) - Basic Linux knowledge
Architecture
Loading diagram…
Step 1 — Create a Key Pair
Warning
Never commit your .pem file to version control. Add it to .gitignore immediately.
Step 2 — Create a Security Group
Step 3 — Launch the Instance
Tip
Use t3.micro for development. For production, start with t3.medium and right-size after 2 weeks of CloudWatch data.
Step 4 — Attach an IAM Role
1
Create the IAM role
2
Attach the policy
3
Create instance profile and attach
Step 5 — SSH and Harden
Once connected, apply hardening:
Verification
Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
| SSH timeout | Security group missing port 22 | Add inbound rule for TCP 22 |
| Permission denied | Wrong key or user | Use correct .pem and AMI username |
| No public IP | Subnet not auto-assigning | Enable auto-assign or use Elastic IP |
| IAM denied | Role not attached | Attach instance profile |