Skip to main content

Amazon EC2 (Elastic Compute Cloud)

Introduction

Amazon EC2 (Elastic Compute Cloud) is one of the core services in AWS that provides virtual servers in the cloud. It belongs to the Infrastructure as a Service (IaaS) model of cloud computing.

In traditional on-premise environments, organizations had to purchase and maintain physical servers. With EC2, developers and system administrators can launch virtual machines on demand, eliminating the need to manage physical hardware.

These virtual machines are called EC2 Instances.
An EC2 instance can run different operating systems such as:

  • Linux distributions (Amazon Linux, Ubuntu, Red Hat, etc.)
  • Windows Server

Developers can launch instances based on their application requirements using the AWS Console, CLI, SDKs, or infrastructure automation tools such as Terraform.


Key Concepts in the EC2 Ecosystem

To effectively work with EC2, it is important to understand several related components and services:

  • AMI (Amazon Machine Image)
  • EBS Volumes
  • Snapshots
  • Auto Scaling
  • Load Balancers
  • Instance connectivity methods

Each of these components plays an important role in building scalable and reliable cloud infrastructure.


EBS Volume (Elastic Block Store)

Amazon Elastic Block Store (EBS) provides block-level storage that can be attached to EC2 instances.

When an EC2 instance is launched, it requires storage for:

  • Operating system files
  • Application binaries
  • Configuration files
  • Logs and runtime data

EBS volumes serve this purpose. They function similarly to SSD or HDD disks attached to a physical server.

Developers can perform standard filesystem operations on EBS volumes such as:

  • Creating files
  • Modifying files
  • Deleting files
  • Installing applications

Because EBS allows direct read and write operations at the block level, it is categorized as block storage.

A simple analogy:

  • EBS → Similar to an SSD disk attached to a laptop or server

Difference Between EBS and S3

Although both EBS and S3 provide storage, they serve different use cases.

EBS (Block Storage)

  • Attached directly to EC2 instances
  • Supports read/write operations like a disk
  • Used for operating systems and application storage
  • Low latency

S3 (Object Storage)

  • Stores data as objects
  • Used for backups, static files, logs, and large datasets
  • Files cannot be modified directly
  • Objects must be re-uploaded to update them

A simple analogy:

  • EBS → Laptop SSD
  • S3 → Cloud storage like Google Drive

Types of EBS Volumes

AWS provides different EBS volume types based on performance and workload requirements.

General Purpose SSD (gp2 / gp3)

General purpose volumes provide balanced performance and cost.

Typical use cases:

  • Development environments
  • Small to medium applications
  • General server workloads

These are the most commonly used volumes.


Provisioned IOPS SSD (io1 / io2)

Provisioned IOPS volumes are designed for high-performance workloads that require consistent disk performance.

IOPS stands for Input/Output Operations Per Second, which measures storage performance.

Typical use cases include:

  • High-performance databases
  • Large production systems
  • Transaction-heavy workloads

Since these volumes provide guaranteed performance, they are more expensive.


Magnetic (Standard HDD)

Magnetic volumes are legacy storage types that offer lower performance compared to SSD volumes.

Characteristics:

  • Lower IOPS
  • Higher latency
  • Mostly replaced by modern SSD-based storage

These volumes are rarely used in modern cloud architectures.


Amazon Machine Image (AMI)

An Amazon Machine Image (AMI) is a template used to launch EC2 instances.

An AMI contains:

  • Operating system
  • Application software
  • Application binaries
  • Configuration settings
  • Additional system components

When a virtual machine is configured with required software and settings, an AMI can be created from that instance.

This AMI can then be used to launch multiple identical EC2 instances, ensuring consistent environments across deployments.

In simple terms:

An AMI is a reusable template for creating EC2 instances.

This concept is similar to creating a snapshot or image of a configured server so that it can be replicated quickly.


Auto Scaling

In production environments, a single EC2 instance is often not sufficient to handle all user requests. Applications must be able to scale automatically based on demand.

Auto Scaling allows AWS to automatically increase or decrease the number of EC2 instances based on workload requirements.

Scaling decisions are typically based on metrics such as:

  • CPU utilization
  • Memory usage
  • Network traffic
  • Request count

For example:

  • If CPU usage exceeds 70%, additional instances can be launched.
  • If the workload decreases, unused instances can be terminated automatically.

This helps achieve:

  • High availability
  • Better performance
  • Cost optimization

Load Balancer

When multiple EC2 instances are running, incoming user traffic must be distributed across those instances.

A Load Balancer distributes incoming requests across multiple EC2 instances to ensure:

  • High availability
  • Fault tolerance
  • Even traffic distribution
  • Improved application performance

AWS provides different types of load balancers:

Application Load Balancer (ALB)

  • Operates at Layer 7 (HTTP/HTTPS)
  • Ideal for web applications and microservices
  • Supports path-based routing

Network Load Balancer (NLB)

  • Operates at Layer 4 (TCP/UDP)
  • Designed for extremely high performance and low latency
  • Handles millions of requests per second

Gateway Load Balancer (GWLB)

  • Used for deploying and scaling network security appliances
  • Typically used in advanced networking architectures

Elasticity vs Scalability

This is a common interview question related to cloud computing.

Scalability

Scalability refers to the ability of a system to handle increasing workloads by adding more resources.

Example:

  • Adding more EC2 instances
  • Increasing instance size

Scalability can be:

  • Vertical scaling (increase instance size)
  • Horizontal scaling (add more instances)

Elasticity

Elasticity refers to the ability of a system to automatically adjust resources up or down based on real-time demand.

Example:

  • Automatically launching additional EC2 instances during peak traffic
  • Automatically terminating instances when demand decreases

Elasticity is typically implemented using Auto Scaling.


interview Answer

  • Scalability is the ability to handle increased workload by adding more resources, whereas Elasticity is the ability to automatically add or remove resources in real time based on demand.

Connecting to EC2 Instances

Developers and administrators can connect to EC2 instances using multiple methods.

Common connection methods include:

  • SSH (for Linux instances)
  • RDP (for Windows instances)
  • AWS Systems Manager Session Manager

When using SSH, public key and private key authentication is used.

A key pair consists of:

  • Public Key – Stored on the EC2 instance
  • Private Key – Stored securely by the user

The private key is used to authenticate and establish a secure connection to the instance.


Summary

Amazon EC2 provides on-demand virtual machines that allow developers and organizations to deploy applications without managing physical infrastructure.

By combining EC2 with services such as:

  • EBS
  • AMI
  • Auto Scaling
  • Load Balancers

AWS enables the creation of highly scalable, reliable, and fault-tolerant cloud architectures.

Understanding these core EC2 components is essential for building modern cloud-native applications.