Understanding Amazon EC2 (Elastic Compute Cloud)
Amazon EC2 is the foundation of AWS compute services—used by startups, enterprises, and developers globally. This chapter explores EC2 in depth: what it is, how it works, its pricing, and how to launch and manage EC2 instances.
What is Amazon EC2?
Amazon EC2 (Elastic Compute Cloud) is a web service that provides resizable, scalable compute capacity in the cloud. Think of EC2 as a virtual server (VM) that you can launch, configure, stop, restart, or terminate as needed.
📌 EC2 allows businesses to run applications without upfront hardware investment and supports Linux/Unix and Windows platforms.
EC2 Key Components
Term | Description |
---|---|
Instance | A virtual server in AWS |
AMI (Amazon Machine Image) | A template with OS + software to launch an instance |
Instance Type | Defines hardware (CPU, RAM, etc.) resources |
Security Group | Acts as a virtual firewall |
Key Pair | SSH authentication mechanism |
Elastic IP | Static IP address for an instance |
EBS Volume | Storage attached to the instance |
EC2 Instance Types
AWS provides a wide variety of instance families, each optimized for different use cases.
Family | Use Case | Examples |
---|---|---|
General Purpose | Balanced CPU/RAM | t2.micro, t3.medium |
Compute Optimized | High-performance CPU | c5.large, c6g.xlarge |
Memory Optimized | RAM-heavy apps | r5.large, x1e.xlarge |
Storage Optimized | Fast IOPS | i3.large, d2.xlarge |
GPU Instances | ML, AI, Graphics | p3.2xlarge, g4dn |
Step-by-Step: Launching an EC2 Instance
1. Go to EC2 Dashboard
- Choose your region
- Click Launch Instance
2. Select an AMI
- Use Amazon Linux 2, Ubuntu, Windows Server, etc.
3. Choose Instance Type
- Select t2.micro for Free Tier
4. Configure Instance
- Default values for testing are okay
- For production: setup subnets, roles, shutdown behavior
5. Add Storage
- Default: 8 GB General Purpose SSD (gp2)
6. Configure Security Group
- Allow port 22 (SSH) for Linux
- Allow port 3389 for Windows (RDP)
- Add HTTP/HTTPS (port 80/443) for web apps
7. Review and Launch
- Select/Create Key Pair (.pem) for SSH
- Click Launch
🔑 Connecting to EC2 (Linux)
ssh -i "your-key.pem" ec2-user@<Public-IP>
🔐 Always secure your .pem file, and set permissions with chmod 400 your-key.pem
.
🧯 Managing EC2 Instances
You can Start, Stop, Reboot, or Terminate instances anytime from the EC2 Dashboard.
Action | Effect |
---|---|
Stop | Shuts down the VM but retains data |
Terminate | Deletes the VM and attached storage (unless preserved) |
Reboot | Restarts the VM |
Elastic IP | Associates a public static IP |
EC2 Pricing Models
Model | Description | Ideal For |
---|---|---|
On-Demand | Pay per second/minute | Short-term workloads |
Reserved Instances | 1 or 3-year commitment for lower cost | Predictable usage |
Spot Instances | Bid for unused capacity (up to 90% off) | Fault-tolerant, flexible apps |
Savings Plans | Flexible pricing for consistent usage | Cost-optimization |
EC2 Auto Scaling
With Auto Scaling, AWS automatically adjusts the number of EC2 instances based on traffic load or performance metrics.
- Create Launch Templates
- Define Scaling Policies
- Integrate with Elastic Load Balancer (ELB)
Security Best Practices for EC2
- Always use SSH key pairs
- Use IAM roles for instance-level access (e.g., access S3 securely)
- Regularly update OS packages
- Enable CloudWatch monitoring
- Use Elastic IP sparingly to avoid cost
- Open only required ports in the security group
📌 Summary
Concept | Summary |
---|---|
What is EC2 | Virtual server in AWS |
AMI & Instance Type | OS template & hardware configuration |
Launching Instance | 7-step process via Console |
Connection Method | SSH or RDP |
Pricing Models | On-Demand, Reserved, Spot, Savings Plans |
Auto Scaling | Automatically handle traffic/load |
Security Practices | Key pairs, IAM roles, security groups |
💡 Explore More AWS Tools & Resources
Educational AI Tutor
Get instant AWS-related answers and explanations using AI.
Interview Question Generator
Generate AWS interview questions for practice and preparation.
AWS Practice Quiz
Test your AWS knowledge with timed quizzes and scoring.
AWS Interview Questions
Browse frequently asked AWS interview questions with answers.