DevOps
Cloud Infrastructure
Amazon Web Services
EC2: Virtual Servers in the Cloud

AWS EC2 (Elastic Compute Cloud)

Amazon EC2 provides resizable compute capacity in the cloud. Think of an EC2 instance as a virtual server that you can launch, configure, and scale in minutes. It is the primary building block for hosting applications, databases, and websites on AWS.


🏗️ The Anatomy of an EC2 Instance

When you launch an EC2 instance, you are configuring several integrated components:

  • AMI (Amazon Machine Image): The "blueprint" or template for your server. It contains the OS (Linux, Windows), software, and configurations.
  • Instance Type: Defines the CPU, memory, storage, and networking capacity of your VM.
  • Security Group: A virtual firewall that controls what traffic can enter or leave your instance.
  • EBS (Elastic Block Store): High-performance block storage volumes used as the "hard drive" for your EC2 instances.

⚡ Choosing the Right Instance Family

AWS provides optimized instance types for every workload. The first letter of the instance name (e.g., t3.micro) tells you the family.

FamilyNameBest For...
T / MGeneral PurposeWeb servers, small databases, development environments.
CCompute OptimizedBatch processing, high-performance web servers, scientific modeling.
RMemory OptimizedHigh-performance databases, real-time big data analytics.
I / DStorage OptimizedDistributed file systems, data warehousing, high-frequency OLTP.

🚀 The Launch Workflow

  1. Choose AMI: Select your OS (e.g., Amazon Linux 2023, Ubuntu 22.04).
  2. Select Instance Type: Choose based on your CPU/RAM requirements.
  3. Configure Network: Assign a VPC and Subnet.
  4. Add Storage: Configure the size and type of your EBS volumes.
  5. Configure Security Group: Open port 22 (SSH) for Linux or 3389 (RDP) for Windows.
  6. Key Pair: Select or create a .pem file for secure login.

🛡️ Best Practices for EC2

  • Elasticity: Use Auto Scaling to automatically add or remove instances based on traffic demand.
  • Reliability: Deploy instances across multiple Availability Zones to ensure high availability if a data center fails.
  • Security: Always use Key Pairs instead of passwords for login, and follow the Principle of Least Privilege for Security Group rules.
  • Cost: Use Spot Instances for flexible workloads to save up to 90% in costs.

[!TIP] Static vs. Dynamic IPs By default, EC2 instances get a "Public IP" that changes every time they stop and start. To have a permanent IP address that stays with your instance forever, use an Elastic IP (EIP).