EC2

Amazon EC2 (Elastic Compute Cloud) is a web service that provides secure, resizable compute capacity in the cloud. It allows you to boot virtual machines, known as EC2 Instances, on demand, giving you complete control over your virtual server hardware, operating systems, and networking layers without requiring physical infrastructure.


Core Infrastructure Components

To launch and run an EC2 instance, you configure a collection of modular infrastructure blocks that define its operating environment:

  • Amazon Machine Image (AMI): A pre-configured template that serves as the blueprint for your instance. It dictates the base operating system (such as Ubuntu, Amazon Linux, or Windows Server) along with initial software packages, libraries, and configuration settings.

  • Instance Types: The specific hardware profile assigned to the virtual machine. Instance types define the physical allocation of CPU cores, RAM size, storage performance, and network bandwidth.

  • Instance Storage: EC2 utilizes two primary storage models. EBS (Elastic Block Store) volumes act as persistent virtual hard drives that can be detached, screenshotted, and survive instance termination. Instance Store volumes provide high-performance, ultra-low latency NVMe storage physically attached to the host server, but they are ephemeral—meaning all data is permanently lost if the instance is stopped or terminated.

  • Networking and Security Groups: Instances are deployed inside a Virtual Private Cloud (VPC) subnet and assigned IP addresses. Security Groups act as virtual firewalls directly covering the instance, enforcing explicit inbound and outbound traffic rules based on specific protocols and port ranges (such as allowing incoming HTTP traffic on port 80 or SSH access on port 22).


Hardware Classification Families

AWS groups EC2 instance types into distinct families tailored to specific computational behaviors:

  • General Purpose (e.g., T4g, M6g): Offers a balanced allocation of compute, memory, and networking resources. This family is the baseline choice for standard workloads like web servers, development environments, and small-to-medium enterprise databases.

  • Compute Optimized (e.g., C6i, C7g): Engineered with high-performance processors. This family features a significantly higher ratio of vCPUs relative to memory, making it ideal for compute-heavy tasks such as media encoding, scientific modeling, machine learning inference, and high-traffic gaming servers.

  • Memory Optimized (e.g., R6g, X2gd): Designed to process massive datasets entirely within volatile RAM. These are optimized for memory-intensive applications, including real-time big data processing analytics, large in-memory caches (like Redis), and heavy relational enterprise databases.

  • Storage Optimized (e.g., I3en, D3): Built specifically for workloads requiring massive, sequential read and write access to huge local storage arrays. They are engineered to maximize Input/Output Operations Per Second (IOPS), targeting distributed file systems, data warehouses, and large NoSQL databases.


Purchasing Models and Cost Management

AWS offers distinct billing frameworks for provisioning EC2 instances, allowing engineering teams to optimize costs based on application uptime characteristics:

  • On-Demand: You pay for compute capacity precisely by the second or hour with absolute flexibility and zero long-term commitments. This is the baseline choice for unpredictable workloads, new application testing phases, or short-term data sorting spikes.

  • Savings Plans / Reserved Instances: In exchange for committing to a continuous, predictable volume of compute usage for a fixed 1-year or 3-year term, AWS provides a significant discount (up to 72%) compared to standard On-Demand pricing. This is critical for stable, production-grade infrastructure that runs 24/7.

  • Spot Instances: Allows you to bid on unused, excess AWS data center capacity at steep discounts (up to 90% off On-Demand rates). However, Spot instances are interruptible. If AWS needs that capacity back for an On-Demand customer, the system issues a strict 2-minute warning before automatically terminating your instance. This model is ideal for stateless microservices, batch processing, background video rendering, or distributed container workers.


Lifecycle States and High Availability

Managing an EC2 instance involves navigating through its operational lifecycle phases:

  • The Lifecycle Loop: When an instance is Stopped, the virtual CPU and RAM allocations are fully released back to the AWS hardware pool, meaning you stop paying for compute hours, though you continue paying for the underlying persistent EBS storage disk. When you transition the instance back to a Running state, it is typically moved to a completely different physical host computer, which automatically assigns it a new dynamic public IP address unless it is anchored by a persistent Elastic IP.

  • Horizontal Scaling: Instead of manually upgrading an individual server's hardware capacity (vertical scaling), modern architectures leverage Auto Scaling Groups. These groups automatically spin up new identical instances behind an Application Load Balancer when performance metrics (like aggregate CPU utilization) spike, and gracefully terminate them when traffic drops, maintaining high application availability while controlling infrastructure spend.