Skip to content

AWS EC2 โ€” Elastic Compute Cloud

Amazon Elastic Compute Cloud (EC2) is the core compute service of AWS, providing resizable virtual machines in the cloud. It is the AWS equivalent of Azure Virtual Machines.

Term Description
Instance A running virtual machine
AMI Amazon Machine Image โ€” the OS + software template for an instance
Instance Type The hardware spec (CPU, RAM, GPU, network)
Key Pair SSH public/private key for secure access
Security Group Stateful firewall controlling inbound/outbound traffic
Elastic IP Static public IP address that you own
User Data Script that runs on first boot to configure the instance
Family Optimized For Example Types
t (General purpose, burstable) Dev/test, low-cost t3.micro, t4g.small
m (General purpose, balanced) Web servers, small databases m6i.large, m7g.xlarge
c (Compute optimized) CPU-intensive apps, HPC c6i.large, c7g.2xlarge
r (Memory optimized) In-memory databases, caches r6i.large, r7g.4xlarge
p / g / trn (Accelerated) ML training, GPU workloads p4d.24xlarge, g5.xlarge
i / d (Storage optimized) High I/O, data warehouses i4i.large, d3.xlarge

t3.micro is included in the AWS Free Tier (750 hours/month for 12 months).

Model Description Best For
On-Demand Pay by the second, no commitment Dev/test, unpredictable workloads
Reserved Instances 1 or 3-year commitment, up to 72% discount Steady-state production workloads
Savings Plans Flexible commitment on compute spend, up to 66% off Flexible reserved-like pricing
Spot Instances Spare capacity at up to 90% discount โ€” can be interrupted Fault-tolerant batch, ML training
Dedicated Hosts Physical server dedicated to you Licensing compliance (Windows Server, SQL Server)
Dedicated Instances Your instances run on dedicated hardware Compliance, isolation
Storage Description Persistence
EBS (Elastic Block Store) Network-attached block storage โ€” primary OS disk Persists after stop/terminate (configurable)
Instance Store Physically attached ephemeral storage Lost when instance stops
EFS (Elastic File System) Shared NFS storage across multiple instances Persistent, shared
S3 Object storage accessed via API Persistent, not a filesystem
Pending โ†’ Running โ†’ Stopping โ†’ Stopped โ†’ Terminated
โ†˜ Rebooting
  • Stop โ€” Saves state, no billing for compute (EBS still billed)
  • Terminate โ€” Permanently deleted (EBS may be deleted depending on config)
  • Reboot โ€” Restarts the OS, instance stays on the same host
  • Each EC2 instance belongs to a VPC and a Subnet
  • Security Groups control traffic (default: deny all inbound)
  • Public instances need an Internet Gateway and a public IP or Elastic IP
  • Private instances use a NAT Gateway for outbound internet access
  • ENI (Elastic Network Interface) โ€” Virtual network card that can be moved between instances

Auto Scaling Groups (ASG) automatically adjust the number of instances based on demand:

  • Define minimum, desired, and maximum instance counts
  • Scale out (add instances) on high CPU/memory/custom metric
  • Scale in (remove instances) when demand drops
  • Integrated with Elastic Load Balancer (ELB) for traffic distribution
Feature AWS EC2 Azure VM
VM image format AMI Azure Managed Image / Marketplace
Disk type EBS (gp3, io2) Managed Disks (Standard SSD, Premium SSD)
Instance metadata 169.254.169.254 IMDS 169.254.169.254 IMDS
Reserved pricing Reserved Instances / Savings Plans Reserved VM Instances
Auto scaling Auto Scaling Group (ASG) Virtual Machine Scale Sets (VMSS)
Load balancer ALB / NLB Azure Load Balancer / Application Gateway
Static IP Elastic IP Static Public IP
Terminal window
# Launch an EC2 instance
aws ec2 run-instances \
--image-id ami-0abcdef1234567890 \
--count 1 \
--instance-type t3.micro \
--key-name my-key-pair \
--security-group-ids sg-0abc123 \
--subnet-id subnet-0abc123
# List running instances
aws ec2 describe-instances \
--filters "Name=instance-state-name,Values=running" \
--query 'Reservations[*].Instances[*].[InstanceId,InstanceType,PublicIpAddress]' \
--output table
# Stop an instance
aws ec2 stop-instances --instance-ids i-0abc1234567890
# Terminate an instance
aws ec2 terminate-instances --instance-ids i-0abc1234567890