πŸ“˜ Amazon EBS (Elastic Block Store): Persistent Block Storage for EC2 Instances

When you launch an Amazon EC2 instance, it’s like booting a virtual server. But what happens to the data when you stop or terminate that instance? That’s where Amazon EBS (Elastic Block Store) comes in.

Amazon EBS is a block-level storage service that provides persistent storage for EC2 instances. Unlike instance store volumes (which are temporary), EBS volumes are durable, high-availability, and scalable.

Think of EBS as the hard drive of your cloud serverβ€”you can attach it, resize it, take snapshots, and even move it between instances.

In this guide, we’ll cover:

  • What Amazon EBS is.
  • Different types of EBS volumes.
  • Hands-on examples with CLI, Python (boto3), and Terraform.
  • Why EBS is important.
  • How to remember for interviews and exams.

πŸ”‘ What is Amazon EBS?

Amazon EBS provides persistent block storage for EC2 instances. Block storage means that data is stored in fixed-size blocks (like sectors on a disk), which makes it ideal for databases, operating systems, and applications that require fast, consistent performance.

Key Features of EBS:

  • Durable: Data persists even if the instance is stopped.
  • Scalable: Resize storage volumes without downtime.
  • High Performance: SSD-backed volumes for IOPS-intensive workloads.
  • Backups: Take point-in-time snapshots to S3.
  • Encryption: Secure data at rest with AWS KMS.

⚑ Types of EBS Volumes

  1. General Purpose SSD (gp3/gp2) β†’ Balanced performance and cost.
  2. Provisioned IOPS SSD (io2/io1) β†’ High-performance databases, transactional workloads.
  3. Throughput Optimized HDD (st1) β†’ Big data, log processing, streaming workloads.
  4. Cold HDD (sc1) β†’ Lowest cost, infrequently accessed data.

πŸ–₯️ Examples of Using Amazon EBS


βœ… Example 1: AWS CLI – Create and Attach EBS Volume

Terminal window
# Step 1: Create a 20GB EBS volume in us-east-1a
aws ec2 create-volume --availability-zone us-east-1a --size 20 --volume-type gp3
# Step 2: Attach volume to EC2 instance
aws ec2 attach-volume --volume-id vol-1234567890abcdef --instance-id i-0123456789abcdef0 --device /dev/sdf

πŸ‘‰ Creates a 20GB gp3 EBS volume and attaches it to an EC2 instance.


βœ… Example 2: Python (boto3) Program – Create and Attach EBS Volume

import boto3
ec2 = boto3.client('ec2', region_name='us-east-1')
# Create a 10GB EBS volume
volume = ec2.create_volume(
AvailabilityZone='us-east-1a',
Size=10,
VolumeType='gp3'
)
print("Created Volume:", volume['VolumeId'])
# Attach the volume to an instance
ec2.attach_volume(
VolumeId=volume['VolumeId'],
InstanceId='i-0123456789abcdef0',
Device='/dev/sdh'
)
print("Attached Volume to EC2 instance")

πŸ‘‰ Automates volume creation + attachment.


βœ… Example 3: Terraform – Create EBS Volume and Attach to Instance

resource "aws_ebs_volume" "example" {
availability_zone = "us-east-1a"
size = 30
type = "gp3"
tags = {
Name = "MyVolume"
}
}
resource "aws_volume_attachment" "attach" {
device_name = "/dev/sdh"
volume_id = aws_ebs_volume.example.id
instance_id = "i-0123456789abcdef0"
}

πŸ‘‰ Creates a 30GB gp3 EBS volume and attaches it to EC2 automatically.


🧠 How to Remember EBS for Interview & Exams

  1. Analogy β†’ Think of EBS as a USB hard drive: you can plug it into your EC2 instance, remove it, and plug it into another instance.
  2. Mnemonic β†’ Remember β€œEBS = Elastic Block Storage = EC2’s Hard Drive”.
  3. Visual Memory β†’ Imagine your laptop without a hard driveβ€”it won’t store anything permanently. Same for EC2 without EBS.

🎯 Why is Amazon EBS Important?

  • Persistence β†’ Data survives EC2 reboots and stops.
  • Performance β†’ Essential for running databases, enterprise apps, and big data workloads.
  • Scalability β†’ Volumes can scale up to 64 TiB.
  • Reliability β†’ Built on replicated infrastructure for durability.
  • Flexibility β†’ Choose between SSDs for performance or HDDs for cost.

πŸ”₯ Interview Questions on Amazon EBS

Q1: What is the difference between EBS and instance store? πŸ‘‰ Instance store is temporary (data lost when instance stops). EBS is persistent.

Q2: What types of EBS volumes exist? πŸ‘‰ gp3/gp2, io2/io1, st1, sc1.

Q3: Can you detach an EBS volume from one instance and attach to another? πŸ‘‰ Yes, as long as it’s in the same Availability Zone.

Q4: How does EBS provide durability? πŸ‘‰ Data is automatically replicated within its AZ.


🌍 Real-World Use Cases

  • Hosting databases like MySQL, PostgreSQL, MongoDB.
  • Running ERP or CRM systems.
  • Storing media files for streaming services.
  • Serving as a boot volume for EC2 instances.
  • Acting as storage for containerized apps in Kubernetes/EKS.

πŸ“– Best Practices for EBS

  • Use gp3 over gp2 β†’ Cheaper and more flexible performance.
  • Take snapshots regularly β†’ Backup data to S3.
  • Encrypt volumes with KMS.
  • Delete unused volumes β†’ Avoid unnecessary charges.
  • Use RAID (striping) for high IOPS needs.

πŸ† Conclusion

Amazon EBS is the backbone of EC2 storage. It provides durable, scalable, and secure block storage that behaves like a traditional hard disk but with the power of the cloud.

Whether you are:

  • Launching a simple web server,
  • Running mission-critical databases, or
  • Archiving logs with low-cost volumes,

EBS ensures your data is safe, persistent, and available.

πŸ‘‰ To remember: EBS = EC2’s Hard Drive.

By mastering Amazon EBS, you not only improve your AWS skills but also strengthen your chances in cloud certifications and interviews.