Amazon Elastic Compute Cloud (EC2) is one of the most widely used AWS services. It lets you run virtual servers in the cloud on demand. This tutorial walks you through the core concepts and practical steps to launch and manage your first EC2 instance.
Amazon EC2 (Elastic Compute Cloud) provides resizable compute capacity in the cloud. Instead of buying and maintaining physical servers, you rent virtual machines (called instances) and pay only for what you use.
| Term | Description |
|---|---|
| AMI (Amazon Machine Image) | A pre-configured template for your instance (OS + software). |
| Instance Type | Defines the CPU, memory, and storage (e.g., t2.micro, m5.large). |
| Key Pair | SSH key used to securely connect to Linux instances. |
| Security Group | A virtual firewall controlling inbound/outbound traffic. |
| Elastic IP | A static public IP address you can attach to an instance. |
| EBS Volume | Persistent block storage attached to an EC2 instance. |
| Region / AZ | Physical data center location. AZ = Availability Zone within a region. |
EC2 instances are grouped into families based on use case:
| Family | Use Case | Example |
|---|---|---|
| General Purpose | Balanced CPU/memory for most workloads | t3.micro, m6i.large |
| Compute Optimized | High CPU-intensive workloads | c6i.xlarge |
| Memory Optimized | Large in-memory datasets (databases, caches) | r6i.2xlarge |
| Storage Optimized | High I/O operations (NoSQL databases) | i3.large |
| Accelerated Computing | GPU/ML workloads | p3.2xlarge, g4dn.xlarge |
Tip: For testing or the AWS Free Tier, use t2.micro or t3.micro (750 hours/month free).
Go to console.aws.amazon.com/ec2 and click Launch Instance.
Select an operating system. For a LAMP stack, choose Amazon Linux 2023 or Ubuntu 24.04 LTS.
Select t2.micro (Free Tier eligible) for testing.
Create or select an existing key pair (.pem file). Download it — you'll need it to SSH into the instance.
Allow at minimum:
Click Launch Instance. Your instance will be running in 1–2 minutes.
For Ubuntu AMIs, use ubuntu instead of ec2-user:
Convert your .pem key to .ppk using PuTTYgen, then connect via PuTTY using your instance's public IP.
From the EC2 dashboard, select your instance → click Connect → use the browser-based terminal.
Security groups act as a virtual firewall. Rules are stateful — allowing inbound traffic also allows the response.
| Rule Type | Port | Source | Use Case |
|---|---|---|---|
| SSH | 22 | My IP | Admin access |
| HTTP | 80 | 0.0.0.0/0 | Public website |
| HTTPS | 443 | 0.0.0.0/0 | Secure website |
| MySQL/Aurora | 3306 | Security group ID | DB from app servers only |