# EC2 Volume Types

## Basics

* [Introduction](https://anon-coders-notes.gitbook.io/techwriterdev/cloud/aws/cloudpractitioner/09_file_storage_solutions)

## EBS

* Elastic Block Store

### Icon

![EBS Icon](https://icon.icepanel.io/AWS/svg/Storage/Elastic-Block-Store.svg)

### About

* Its a **network drive storage** that can be attached to instances while they run.
* An EC2 instance can have multiple EBS volumes attached to it at a time.
* Can persist data even after instance termination.
* They can be detached from one EC2 instance to another EC2 instance fairly quickly.
* **They are bound to specific availability zone. To move an EBS volume from one availability zone to another, one can take a snapshot and create an EBS volume out of the snapshot**.
* While creation itself EBS volume's size and IOPS should be allocated and billing is done based on their selection. These attributes can be changed over time.
* By default, a root EBS volume of EC2 instance is deleted, when EC2 instance is terminated. But other EBS volumes attached are not deleted on EC2 termination. However, this behavior for root EBS volume can be changed if need be.
* Can be attached to multiple EC2 instance at a time *(multi-attach)*.
* There are three volume types
  * SSD
  * HDD
  * Previous generation

### EBS Volume Types

* There are six EBS volume types.
* More details about volume types can be found [here](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html).
* Characterized in size, throughput and IOPS.

#### gp2/gp3

* **General purpose** SSD volume, that balances price and performance.
* Can be used as boot volumes for EC2.
* Size varies from 1GiB - 16TiB.
* gp3 is newer version of volumes.
  * **Can increase IOPS upto 16,000 and throughput upto 1000 MiB/s independently**.
  * Baseline of 3000 IOPS and throughput of 125 MiB/s.
* gp2 is older version of volumes.
  * Small gp2 volumes can burst IOPS uptp 3,000.
  * **Size of volume and IOPS are linked, max IOPS is 16,000**.
  * 3 IOPS per GB, means at 5334 GB we are at max IOPS.

#### io1/io2

* Highest performance SSD volume.
* Recommended for mission-critical low-latency or high-throughput workloads.
* Can be used as boot volumes for EC2.

**Provisioned IOPS**

* Critical for business application with sustained IOPS performance.
* **Recommended for application that needs more than 16,000 IOPS**.
* Great for database workloads.
* io/io2 volumes falls under this category.
* The volumes of this kind supports multi-attach feature.

**io1**

* Size varies from 4GiB - 16TiB.
* **Max PIOPS can be upto 64,000 for Nitro EC2 instance and 32,000 for other**.
* Can increase PIOPS independently from storage size.

**io2**

* Size varies from 4GiB - 64TiB.
* Sub-millisecond latency.
* Max PIOPS can be upto 256,000 with IOPS:GiB ratio of 1,000:1.
* Can increase PIOPS independently from storage size.

**Multi-attach**

* **Supports EBS multi-attach, where an EBS volume can be attached to multiple EC2 instance&#x20;*****(upto 16 instances at a time)*****&#x20;in the same AZ for io1/io2 volume types**.
* Each instance has full read and write permission to the volume.
* Use case include achieve higher application availability in clustered Linux applications. Applications must manage concurrent write operations.
* Upto **16 EC2 instances at a time** can be attached.
* When using multi-attach feature of this volume type, make sure to use [cluster-aware](https://en.wikipedia.org/wiki/Clustered_file_system) file system.

#### st1

* Low cost HDD volume designed for frequently accessed, throughput-intensive loads.
* It is throughput optimized.
* **Cannot be a boot volume**.
* Size varies from 125GiB - 16TiB.
* Max throughput is 500MiB/s - max IOPS 500.

#### sc1

* Cold HDD.
* Lowest cost HDD volume designed for less frequently accessed workloads.
* Used for data archival requirement.
* **Cannot be a boot volume**.
* Max throughput is 250MiB/s - max IOPS 250.

> Note: Only gp2/gp3 and io1/io2 can be used as boot volume for EC2 instance.

### Snapshots

* Allows backup of a EBS volume at a point in time.
* Though not necessary, it is recommended to detach EBS volume while taking snapshot.
* **This allows EBS volume to be copied across different availability zone or region**.

#### Features

**EBS Snapshot Archive**

* Allows you to move a snapshot to `archive tier`, which is 75% cheaper.
* Can take from 24 hours upto 72 hours to restore the snapshot.

**Recycle bin**

* One can setup rules to retain deleted snapshots so that you can recover deleted snapshot.
* Retention period can be from 1 day upto 1 year by creating retention rule.
* Retention rule can be locked from accidental modification.

**Fast snapshot restore (FSR)**

* Allows forceful initialization of snapshot to have no latency on first use.
* Expensive
* Useful when EBS volume has huge size and need to be initialized quickly.

***

## Instance store

* An instance store provides temporary block-level storage for your instance.
* This storage is located on disks that are physically attached to the host computer.
* Better I/O performance *(IOPS)*.
* Also known as `ephemeral storage` because once EC2 instance is stopped or terminated, data contained in the store are lost. However, data on the store persists in case of a reboot.
* Some events during an EC2 instance life cycle may result in data erasure. More details can be found [here](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#instance-store-lifetime).
* Unlike `EBS`, Instance store volumes are attached only at instance launch, and they cannot be detached from one EC2 instance to another.
* Risk of data loss due to hardware failure is possible, hence backup and replication should be user's responsibility.

***

## EFS

* Elastic File Storage

### Icon

![EFS Icon](https://icon.icepanel.io/AWS/svg/Storage/EFS.svg)

### About

* Managed NFS *(Network File System)* which uses `NFSv4.1` protocol that can be mounted on many EC2 instances.
* EFS can be mounted on hundreds of EC2 instances which are in different availability zone.
* **Only applicable to Linux instances**.
* Highly available, Scalable and Expensive with pay per use payment model.
* As it is scalable, the file system will scale automatically upto Petabyte scale compared to EBS.
  * Supports 1000s of concurrent NFS client.
  * Upto 10 GB/s of throughput
* Use cases include - content management, web serving, data sharing, Wordpress etc.
* **Compatible with Linux based AMI&#x20;*****(not windows)***.
* Supports encryption at rest using KMS.
* It has different `Performance mode` which can be set at creation time,
  * **General purpose** : This is the default mode, useful for latency sensitive scenario.
  * **Max I/O** : Useful for higher latency, higher thoughput, highly parallel use cases like big data, media processing.
* It supports `Throughput mode` such as,
  * **Bursting** - For 1 TB of storage, you can get 50 MiB/s, with burst upto 100 MiB/s, as storage grows. As storage grows throughput grows.
  * **Provisioned** - Consistent throughput regardless of storage size. Storage size and throughput are not connected. Has to pay for the provisioned throughput capacity.
  * **Elastic** - Automatically scales throughput based on the workload, making it a great fit for unpredictable workloads.
    * For ex: Upto 3GiB/s for reads and 1 GiB/s for writes based on workload.
    * Recommended

### Storage class

#### Based on Lifecycle

* This feature allows to move file to different tiers based on frequency of access of files.
* This is configured through lifecycle management policy.

**Standard/Regional**

* Can be used for frequently accessed files.
* These are multi-AZ with backups stored across multiple AZ.

**Infrequent Access (IA)**

* Can be used to store files at lower price.
* Cost to retrieval of files is high.

**Archive**

* Rarely accessed data can be stored here.
* It is `50%` cheaper to store the data.

#### Based on durability and availability

**OneZone**

* Can be accessed only in one availability zone.
* Backup is enabled by default and is stored in the same AZ as the original file.
* Can be used for frequently accessed files but does not require high availability or durability.

**OneZone IA**

* Can be used for long lived, infrequently accessed files but does not require high availability or durability.
* Over `90%` cost savings.

## Difference between EFS and EBS

| Features                              | EBS                                                                     | EFS                                 |
| ------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------- |
| Acronym                               | Elastic Block Store                                                     | Elastic File Storage                |
| Service Type                          | Availability Zone                                                       | Regional                            |
| Multi-Attach                          | Supported only by io1/io2                                               | Supported                           |
| Migration strategy                    | Create a snapshot in one AZ and restore in another                      | Not need as its regional by default |
| Backup Strategy                       | Create Snapshot, should not backup while handling too much traffic      | Incremental backup                  |
| Delete on termination of EC2 instance | Yes, if it is a root volume and configured to be deleted on termination | No                                  |
| Storage class                         | Not supported                                                           | Supported                           |
| Volume type                           | Yes                                                                     | Not a volume based storage          |
