Elastic Block Store(EBS)
Published: 2023-06-23 14:42:46

We previously learnt how to create an EC2 instance and connect to it. you can recap [here](https://dev.to/jeptoo/how-to-create-ec2-instance-ubuntu-2204-on-aws-and-connect-via-ssh-using-pem-492o).

While still on this there are two types of storage in EC2:

 i) **In Memory(instance store)** - which provides temporary block-level storage that is directly attached to the EC2 instance. It is ideal for temporary data, cache, or scratch space that doesn't need to persist beyond the lifespan of the instance.

 ii) **EBS( elastic block store)** - provides persistent block-level storage volumes that can be attached to EC2 instances. It offers durable and reliable storage that persists independently of the instance's lifespan.

Let us dive more into EBS.

- Amazon Elastic Block Store (EBS) provides storage volumes for use with EC2 instances. These volumes act like raw, unformatted block devices that can be mounted on your instances. They persist independently from the life of the instance. You can create a file system or use them like a hard drive. EBS volumes offer fast access to data and long-term persistence, making them great for file systems, databases, and applications that need frequent updates and direct access to block-level storage. They work well for both random reads and writes and continuous read and write operations.

## Features of EBS

a). EBS provides _General Purpose SSD_, _Provisioned IOPS SSD_, _Throughput Optimized HDD_, and _Cold HDD_ as volume types.

   - _General Purpose SSD volumes (gp2 and gp3)_:
     - Ideal for transactional workloads.
     - Balance price and performance.
     - Suitable for boot volumes, medium-size single instance databases, and development/test environments.


   - _Provisioned IOPS SSD volumes (io1 and io2)_:
     - Designed for I/O-intensive workloads.
     - Offer consistent and predictable IOPS rate.
     - Scale to tens of thousands of IOPS per instance.
     - io2 volumes provide highest volume durability.


   - _Throughput Optimized HDD volumes (st1)_:
     - Low-cost magnetic storage.
     - Performance measured in terms of throughput.
     - Suitable for large, sequential workloads like Amazon EMR, ETL, data warehouses, and log processing.

   - _Cold HDD volumes (sc1)_:
     - Low-cost magnetic storage.
     - Performance measured in terms of throughput.
     - Ideal for large, sequential, infrequently accessed data.
     - Cost-effective solution for storing cold data.

b). EBS Volume Encryption - This allows one to encrypt their EBS volumes to meet data-at-rest encryption requirements for regulated or audited data. It also ensures that the stored data in the volume. disk I/O and snapshot is encrypted.
- Encryption happens on the servers hosting EC2 instance which secures data both at rest and during transit.


c). EBS Snapshots allows you to create point-in-time copies of your EBS volumes which are stored in S3. The snapshot provide long-term durability and serve as a starting point for new EBS volumes.
- The same snapshot can be used to create multiple volumes as needed and the snapshots can be copied across different AWS Regions. 

d). Performance Metrics such as _bandwidth_,  _latency_, and _average queue length_ are provided by Amazon Cloudwatch and it allows you to monitor the performance of your EBS volume.
- Monitoring helps ensure that you are allocating sufficient performance resources for your applications without paying for unnecessary resources.

e). When you create an EBS volume, it is linked to a specific Availability Zone (AZ). This means that the volume is located in a particular data center within a specific geographic region. However, if you want to use the volume in a different AZ within the same AWS Region, you can create a snapshot.

- A snapshot is a copy of your EBS volume's data and settings. It captures all the information stored on the volume at a specific point in time. By creating a snapshot, you essentially create a backup of your volume.

- Once you have a snapshot, you can use it to restore the volume to a new EBS volume in any AZ within the same AWS Region. This means you can move your volume's data from one AZ to another without losing any information. The restored volume will have the same data and settings as the original volume at the time the snapshot was taken.


### Creating EBS Volume

AWS allows us to create a volume from either of the following three methods:

i) Create and attach EBS volumes while creating an EC2 instance using the Launch Instance wizard.
ii) Create an empty EBS volume, and later you can attach it to a running instance.
iii) Create an EBS volume from a previously created snapshot, and later you can attach it to a running instance.


_**We are going to use option 2 to create EBS**_

**STEPS**
-  On the **EC2 Dashboard** select the **Elastic Block Store → Volumes** service on the left navigation pane.
-  Select the **Create Volume** button as on the screenshot below:

![dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dkq31mumcnd4i4v10wp4.png)

- Specify the volume details on the set-up wizard page. 
- You will have to specify the following details:

   i)Volume type - AWS offers various types of volumes, as described in the table below.
   ii)Size (GB) - Mention the size with-in limits of the type you have chosen above.
   iii) Availability Zone - It has a default value, or you can choose your preferred AZ.
   iv)Snapshot ID - Specify the ID of the snapshot if you wish to create a volume from an existing snapshot. Remember, a snapshot is the saved state of another volume at a particular moment.
   v) Tag - Specify the key-value pair, such as {Name: U-test}
   

![details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nn38jw3dqzg3py9ig0ak.png)

- Click on the Create Volume and your EBS will be created.

**EBS Dashboard**
- On the EC2 Dashboard select the **Elastic Block Store → Volumes** service in the left navigation pane.

![ebsdashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2pnqld0x17i7gy744u1j.png)

**List of all Volumes**

- On the image above it is labeled as 1, here you can view all the volumes available under your account in a specific region. 

There is ID, size, type, I/O per second, snapshot ID of that volume, date of creation, availability zone, current status, whether the volume is encrypted and the EC2 instance to which it is attached.

- You can do several operations after creating a volume which includes:
   - Attach a volume to one or more EC2 instance(s)
   - Detach a volume from an instance
   - Replace a volume
   - View the volume details, and monitor the current status
   - Delete a volume

**Details of Selected Volume**

This is the second part of the EBS Dashboard, Select the checkbox against the name of any volume.

- _Details_ - you can view the specific information, such as volume ID, snapshot ID, size, date of creation, instance to which it is attached, type of volume, and much more.

- _Status Check_ - Here you can view the health status of the selected volume. There are four possible status: Okay, Warning, Impairedor insufficient-data. See more details about the status [here](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitoring-volume-status.html). You can view IO status, pre-defined IO performance, dates, and further textual description (selective).

![status](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l640zu51d6me14jgh0zr.png)

- Monitoring - Here you can view the I/O performance metrics for the selected volume, such as:
   - read/write bandwidth (kB/sec),
   - read/write throughput (Operations/sec),
   - average queue (Operations)
   - Idle time (%)
   - avg read/write size (kB/Operation)
   - avg read/write latency (msec/Operation)

![monitoring](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/banxcdoz4gga56vrf4ym.png)


- _Tags_ - Here, you can have a look at the associated tag. In the snapshot above, it shows the Name tag with _U-test_ value.

![tags](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/687qb87z2cjsvgj47tnp.png)


## Conclusion

- Amazon Elastic Block Store (EBS) provides versatile storage for Amazon EC2 instances. With features like volume encryption, snapshots, and performance monitoring, EBS offers secure data-at-rest, reliable backups, and efficient resource allocation. It allows flexibility by associating volumes with Availability Zones (AZs) and restoring snapshots to different AZs within the same AWS Region for workload distribution, migration, and disaster recovery. EBS is essential for scalable and reliable architectures on AWS.
- You can read more on EBS [here](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html)