Amazon Web Services
Compute
- AWS EC2
- EC2 Instance Types
- EC2 Pricing Models
- EC2 Auto Scaling
- Elastic Load Balancing-ELB
- AWS Lambda β Serverless Computing
- Amazon Lightsail
- AWS Elastic Beanstalk
- AWS Fargate
- Amazon ECS (Elastic Container Service)
- Amazon EKS (Elastic Kubernetes Service)
DynamoDB
- DynamoDB Global Table vs Regular DynamoDB Table
- DynamoDB Streams
- Athena query data to DynamoDB
- Athena Query Results with DynamoDB
- PySpark DataFrame to DynamoDB
Redshift
Lambda
Glue
Lambda
Storage
- S3 vs. EBS vs. EFS
- Amazon S3 (Simple Storage Service)
- Amazon S3 Storage Classes
- Amazon EBS (Elastic Block Store)
- Amazon EFS (Elastic File System)
- AWS Storage Gateway
- AWS Snowball
- Amazon FSx
- AWS Backup
Security
π 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
- General Purpose SSD (gp3/gp2) β Balanced performance and cost.
- Provisioned IOPS SSD (io2/io1) β High-performance databases, transactional workloads.
- Throughput Optimized HDD (st1) β Big data, log processing, streaming workloads.
- Cold HDD (sc1) β Lowest cost, infrequently accessed data.
π₯οΈ Examples of Using Amazon EBS
β Example 1: AWS CLI β Create and Attach EBS Volume
# Step 1: Create a 20GB EBS volume in us-east-1aaws ec2 create-volume --availability-zone us-east-1a --size 20 --volume-type gp3
# Step 2: Attach volume to EC2 instanceaws 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 volumevolume = ec2.create_volume( AvailabilityZone='us-east-1a', Size=10, VolumeType='gp3')print("Created Volume:", volume['VolumeId'])
# Attach the volume to an instanceec2.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
- 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.
- Mnemonic β Remember βEBS = Elastic Block Storage = EC2βs Hard Driveβ.
- 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.