Table of Contents
In this tutorial, we will learn about Amazon Elastic Block Store. First, we will go through the theoretical concepts that include a brief overview of Amazon EBS, its benefits, and volume types. Then we will do a hands-on that will focus on EBS volumes and snapshots. Now let's dive deep into the topic!
Amazon Elastic Block Store (AWS EBS) Overview
According to the official documentation of AWS.
Amazon Elastic Block Store (Amazon EBS) provides block level storage volumes for use with EC2 instances. EBS volumes behave like raw, unformatted block devices. You can mount these volumes as devices on your instances. EBS volumes that are attached to an instance are exposed as storage volumes that persist independently from the life of the instance. You can create a file system on top of these volumes, or use them in any way you would use a block device (such as a hard drive). You can dynamically change the configuration of a volume attached to an instance.
Benefits of AWS EBS volumes
Following is a brief overview of the benefits of using EBS volumes.
- Data availability is one of the benefits of using EBS volumes. To prevent data loss due to failure of any single hardware component, EBS volume is automatically replicated within its Availability Zone when created.
- EBS volume can persist independently from the life of an EC2 instance resulting in data persistence. Note that the Delete on termination check box should be unchecked when attaching the volume to an instance.
- We can create encrypted EBS volumes with the Amazon EBS encryption feature for simplified data encryption. Amazon EBS encryption uses 256-bit Advanced Encryption Standard algorithms (AES-256) and an Amazon-managed key infrastructure.
- We can create snapshots with Amazon Elastic Block Store volumes and write a copy of the data in the volume to Amazon S3, where it is stored redundantly in multiple AZs. We can create new EBS volumes from these snapshots and can also move volumes across AZs.
- We can do live configuration changes with EBS volume because of its flexibility. Volume type, volume size, and IOPS capacity can be modified without service interruptions.
For more information related to the benefits of Amazon EBS volumes, we can visit the official documentation of AWS.
AWS EBS volume types
Through different Amazon Elastic Block Store volume types, we can tailor our storage performance and cost to the needs of our application as it provides volumes that differ in performance characteristics and price. Let's have a brief overview of the different volume types provided by AWS.
1 - Solid state drives (SSD)
SSD is optimized for transactional workloads involving frequent read/write operations with small I/O size, where the dominant performance attribute is IOPS. The SSD-backed volumes have two categories i.e. Purpose SSD and Provisioned IOPS SSD. General Purpose SSD provides a balance of price and performance and is recommended for most workloads whereas Provisioned IOPS SSD provides high performance for mission-critical, low-latency, or high-throughput workloads.
2 - Hard disk drives (HDD)
HDD is optimized for large streaming workloads where the dominant performance attribute is throughput. The HDD-backed volumes have two categories i.e. Throughput Optimized HDD and Cold HDD. Throughput Optimized HDD is a low-cost HDD designed for frequently accessed, throughput-intensive workloads whereas Cold HDD is the lowest-cost HDD design for less frequently accessed workloads.
3 - Previous generation
EBS Magnetic volumes are previous generation volume types that are backed by hard disk drives (HDDs) and can be used for workloads with smaller datasets where data is accessed infrequently or when performance consistency isn't of primary importance. EBS Magnetic volumes provide approximately 100 IOPS on average, with an ability to burst to hundreds of IOPS, and support volumes from 1GB to 1TB in size. However, it is recommended to use a current-generation volume type instead.
For more information related to Amazon EBS volume type, we can visit the official documentation of AWS.
Create Amazon EBS volume
First, we will log in to our AWS account then select EC2 under the Services tab. From the left pane, we can find Volumes under Elastic Block Store. Currently, we have no EBS volumes created. We will click on Create volume.
We will select the volume type to be General Purpose SSD (gp2). We will set the size of our EBS volume to be 2 GiB. Note that we are creating our EBS volume in us-east-2a Availability Zone which means it can only be attached to EC2 instances lying in the same Availability Zone. Then we will click on Create volume.
Attach EBS volume to EC2 instance
Now we will create an EC2 instance. We learned to create an EC2 instance in one of our previous tutorials. Now we will look at the storage details of our newly created EC2 instance. Here we can see that the Root device type is EBS and the volume will be deleted on EC2 instance termination since we did not uncheck the check box for Delete on termination while creating our EC2 instance. Now we will attach our Amazon Elastic Block Store volume to the newly created EC2 instance.
We have two Amazon Elastic Block Store volumes now. First is the one that we have just created and the other one is the root volume of our EC2 instance, note that its state is In-use. Now we will click on Attach volume.
This will redirect us to the following screen. Here we can select EC2 instances in us-east-2a Availability zone. Our Ec2 instance lies in the same AZ so we will select it. Then we will click on Attach volume.
Now we can view two volumes under the Storage tab of our EC2 instance. Note that our attached Amazon Elastic Block Store volume will not delete on termination of our EC2 instance, hence the data will persist.
Terminate EC2 instance
Now after terminating our EC2 instance we can see that our EBS volume is still there and has not been deleted on termination. Note that its state has changed from In-use to Available.
Create Amazon EBS Snapshot
We can create point-in-time snapshots to back up the data on our EBS volumes to Amazon S3. Snapshots are incremental backups, which means that only the blocks on the device that have changed after your most recent snapshot are saved. Now we will create a snapshot of our Amazon Elastic Block Store volume.
Here we will provide the description of our snapshot. Now we will click on Create Snapshot.
Here we can view our newly created snapshot.
Copy Amazon EBS Snapshot
We can copy our snapshot from our AWS Region to another or within the same region. Now we will click on Copy snapshot.
Here we will select our desired region i.e. us-west-1 where we want our snapshot to be copied. Note that originally the volume from which this snapshot was created lied in us-east-2. Now we will click on Copy snapshot.
Here we can view our newly created snapshot in us-west-1.
Create Amazon EBS Volume from Snapshot
Now we will learn to create Amazon Elastic Block Store volume from our snapshot. We will click on Create volume from snapshot. Note that this is the snapshot that we created earlier in us-east-2a.
Here we can select a different Availability zone other than where it was originally in and then we can attach that EBS volume to our EC2 instance in that AZ.
Now we can see that we have two EBS volumes one in us-east-2a and the other in us-east-2b.
With this, we have come to the end of our tutorial on the Amazon Elastic Block Store. In this tutorial, we learned about Amazon EBS, its benefits, and volume types. After that, we walked through the process of the creation of EBS volumes. Then we learned that how we can attach an EBS volume to an EC2 instance. We also observed that what happens to the attached EBS volumes on termination of an EC2 instance. We learned about EBS snapshots and walked through the process of its creation. After that, we learned that how we can copy an EBS volume to another region. Lastly, we learned that how we can create EBS volumes from EBS snapshots.
Stay tuned for some more informative tutorials coming ahead. Feel free to share your feedback in the comments section and do let us know if you want to learn about any topic on AWS.