AWS Part 2 — Understanding AWS EBS Volumes
Prerequisites :
Introduction to EBS
Types of EBS Volume
Creating an EBS Volume and attaching it to an EC2 instance
Changing the size of existing EBS volume without downtime
Snapshots and Backups
Cleanup all resources We will do everything with the hands-on tutorial on AWS Console.
Introduction to AWS EBS (Elastic Block Store)
When using a Windows laptop, you have storage (such as SSD or HDD) on C-Drive, D-drive, etc.
Just like your computer has storage drives, an EC2 instance also has storage. When we created our EC2 instance earlier, it came with 8 GB of gp3 storage by default, which we didn't change.
It was an EBS volume of 8 GB.
There are generally two kinds of storage types in EC2 servers:
Instance Store
EBS Volumes
Instance Store
This storage type is directly connected to the host machine (EC2). Data is lost when the instance stops or ends.
Use Case: It's great for temporary data that changes often, like caches or buffers.
Because it's directly attached, it offers high performance since data doesn't need to travel far.
EBS Volumes
Imagine it like an external hard drive connected to your EC2 instance. You can attach or detach it whenever you want. If your instance is terminated, your EBS volume remains safe and can be attached to another EC2 instance.
Good for databases, file systems, or applications needing permanent storage.
An Instance Store is part of the EC2 machine itself, while an EBS volume is located separately and connects virtually to the EC2 instance, with data traveling over a network, similar to Bluetooth data transfer between two mobiles.
The Instance Store, being inside the EC2 machine, offers low latency but loses data when the instance is terminated, whereas EBS is more reliable as its data persists even after termination.
Important Note: An EBS volume can only be attached to an EC2 instance within the same Availability Zone where it was created, such as an EBS volume in ap-south-1b being attachable only to an EC2 instance in ap-south-1b.
Types of EBS Volumes
AWS provides different kinds of EBS volume with different pricing and we can choose anyone based on the type of application we are building.
The below data is taken from AWS documentation. No need to remember these.
General purpose SSD (gp2 and gp3) is suitable for general tasks, with gp2 offering up to 16,000 IOPS and 1,000 MB/s throughput, while gp3 provides up to 16,000 IOPS with performance scaling linearly with volume size at 3 IOPS per GB, reaching up to 16,000 IOPS at 5,334 GB.
Provisioned IOPS SSD (io1 and io2): These are high-performance SSDs for important apps needing steady and fast IOPS. They are great for big databases like SQL Server, Oracle, and MySQL that require high IOPS and stable performance. io2 is more durable (99.999% durability) and performs better than io1, offering up to 64,000 IOPS and 1,000 MB/s throughput. io1 also provides up to 64,000 IOPS and 1,000 MB/s throughput, and you can set an IOPS rate when creating it.
Throughput Optmizatized HDD (st1)
Cold HDD (st2)
Creating an EBS Volume and attaching it to an EC2 instance
1.We will launch our EC2 Instance (called EC2 Instance 1) with a default EBS Volume of 9 GB. Press enter or click to view image in full size.
2. We will attach another external 4 GB EBS Volume and attach to this EC2 Instance 1.
3. Download a code from GitHub to this external EBS Volume of 4GB.
4.Delete EC2 Instance 1, ensuring the default 9 GB EBS Volume is preserved by selecting the "not delete" option during launch; then, launch EC2 Instance 2 with a 10 GB root volume, attach the previous EBS volume, and verify if the downloaded code persists.
5.Launch another EC2 Instance 2 with a 10 GB root volume. Attach the previous EBS volume to this new instance and check if the downloaded code is still there.
Changing the size of existing EBS volume without downtime
Select the EBS Volume by clicking the checkbox
Click to “Action” button on the top right corner
Click on resize volume then give the new volume size.
Note: You can only increase the size, which means if you have initially given 4 GB then you can only give a size which is greater than 4GB.Now, SSH to your EC2 instance and type the below command
resize2fs /dev/xvdf
5. Your volume has been resized. You can check your new size that has been increased from the below command:
df -h
Snapshots and Backups
Let's start with an example. You probably know the basics of git. In git, when we make changes, we "commit" them. Commits help us track changes. If a feature we're building isn't good, we can go back to an earlier commit. This helps us keep a history. Similarly, when we change our EBS Volume, like downloading or deleting data, we can create a snapshot. A snapshot is separate. With it, we can make a new EBS Volume that has all the data from when the snapshot was taken. If our volumes get deleted, we won't lose data because we have a snapshot. We can create another EBS Volume with all the data using the snapshot. Snapshots are also used for data backup. Some companies take snapshots of their EBS Volume every night. This way, they have daily data backups. Snapshots have another advantage. They are region-specific. A snapshot from ap-south-1a or ap-south-1b will be in the region ap-south-1. You can create an EBS Volume in any availability zone of that region using the snapshot. If you want to attach an EBS Volume from ap-south-1a to an EC2 instance in ap-south-1b, create a snapshot of the ap-south-1a EBS Volume. Then, launch a new EBS Volume in ap-south-1b using the snapshot and attach it to the instance in ap-south-1b. Try this as homework.
