EC2 - Elastic Compute Cloud
EC2 provides resizable virtual servers in the cloud. You choose instance type, OS, and pay per second of runtime.
What is AWS EC2 (Elastic Compute Cloud)?
EC2 (Elastic Compute Cloud) is AWS's virtual machine service. Each EC2 instance is a virtual server running on AWS hardware. You select the instance type (defining CPU, RAM, network, storage), the AMI (Amazon Machine Image - your OS + software), and the region.
Instance Types
Instance types follow the naming pattern family.size - e.g., t3.medium, m6i.xlarge, c7g.2xlarge.
| Family | Optimised For | Example Use |
|---|---|---|
| t (burstable) | Low baseline CPU with burst | Dev/test, low-traffic web |
| m (general) | Balanced CPU/RAM | Application servers |
| c (compute) | High CPU | Encoding, ML inference, HPC |
| r (memory) | High RAM | In-memory DBs, analytics |
| i (storage) | High IOPS NVMe | Databases, caches |
| p/g (GPU) | GPU compute | ML training, rendering |
| x (extra memory) | Extreme RAM (up to 24 TB) | SAP HANA, in-memory analytics |
Sizes within a family: nano -> micro -> small -> medium -> large -> xlarge -> 2xlarge -> ... -> 48xlarge.
Purchasing Options
| Option | Description | Savings vs On-Demand |
|---|---|---|
| On-Demand | Pay per second, no commitment | Baseline (0%) |
| Reserved (1 or 3 yr) | Commit to instance family + region | Up to 72% |
| Savings Plans | Flexible reserved - commit to $/hr spend | Up to 66% |
| Spot | Spare AWS capacity, interruptible (2 min notice) | Up to 90% |
| Dedicated Host | Physical server for your use | For licensing compliance |
Spot interruption: AWS reclaims spot capacity with 2 minutes notice. Use for stateless, fault-tolerant workloads - batch jobs, CI runners, ML training checkpoints.
Storage
- Instance store: Ephemeral NVMe directly on the host. Extremely fast. Lost when instance stops.
- EBS (Elastic Block Store): Persistent network-attached volumes. Survives stop/start. Multiple volume types (gp3, io2, st1, sc1).
- EFS: Shared NFS file system mountable across many instances.
AMIs (Amazon Machine Images)
AMIs snapshot the root volume + launch config. You can use AWS-provided AMIs (Amazon Linux 2/2023, Ubuntu, Windows), third-party marketplace AMIs, or custom AMIs you create from existing instances (for pre-baked environments).
Auto Scaling Groups (ASG)
ASG manages a fleet of EC2 instances:
- Define min/desired/max instance count
- Launch template specifies instance type, AMI, user data
- Scaling policies: target tracking (maintain 60% CPU), step scaling, scheduled
- Health checks: EC2 status checks or ELB health checks replace unhealthy instances
ASG is the primary EC2 horizontal scaling mechanism.
Placement Groups
| Type | Behaviour | Use For |
|---|---|---|
| Cluster | All instances in same rack | Low-latency HPC, 10Gbps between instances |
| Spread | Instances on separate hardware | Critical instances needing fault isolation |
| Partition | Groups in separate racks | Distributed systems (Kafka, Cassandra) |
Key Networking
- Each instance gets a private IP within its VPC subnet
- Public IP (if configured) is ephemeral - changes on stop/start. Use Elastic IP for a static public address.
- Security groups = stateful firewall at the instance level (allow rules only)
- NACLs = stateless firewall at the subnet level (allow + deny rules)
Interview Angle
EC2 questions often focus on cost optimisation (on-demand vs reserved vs spot), instance family selection (right-size for the workload), and scaling patterns (ASG + ALB). For stateless services, spot + ASG gives up to 90% savings. For databases, reserved or savings plans. Always mention that t3 instances have CPU credits - sustained high CPU workloads should use m or c family instead.
Recommended Resources
AWS Solutions Architect Course
Comprehensive SAA-C03 prep with hands-on labs and practice exams.
AWS Solutions Architect Study Guide (SAA-C03)
900 practice questions + full SAA-C03 coverage by Sybex.
AWS Cloud Practitioner Study Guide (CLF-C02)
500 practice questions for the AWS Foundational certification.
AWS AI Practitioner Study Guide (AIF-C01)
Foundational prep for the AWS Certified AI Practitioner exam.
Ultimate AWS Certified Developer Associate 2026 (DVA-C02)
Top-rated DVA-C02 course by Stephane Maarek - hands-on labs and practice tests.
Ultimate AWS Certified AI Practitioner AIF-C01
Foundational AI/ML on AWS - Bedrock, SageMaker, and generative AI concepts.
AWS Certified Machine Learning Engineer Associate (MLA-C01)
Hands-on MLA-C01 prep covering MLOps, model deployment, and AWS AI services.
A Cloud Guru - AWS
Video-first cloud training with sandbox environments.