# EBS, EFS and instance store

Choose block, shared-file or temporary storage, then verify encryption, snapshots and cleanup with the AWS CLI.

Course: [AWS for DevOps](https://devops.rajeev.pro/courses/aws), lesson 7. About 25 minutes, intermediate. Source: https://devops.rajeev.pro/courses/aws/07-storage-types

## What you will learn

- Choose between EBS, EFS and instance store for a workload.
- Compare gp3, io2, st1 and sc1 at a high level.
- Create an encrypted EBS volume and snapshot it safely.
- Explain why EFS needs mount targets before an instance can mount it.
- Describe how AWS Backup differs from a single EBS snapshot.

## The storage decision

Before choosing a disk, ask what the application needs to store and how it will access it. A database needs a
block device with predictable latency; a shared web fleet may need many servers to see the same files; a cache
may be disposable. Picking by product name alone can leave data unavailable after a failure or add unnecessary
cost.

AWS offers three common shapes here: EBS is a persistent block device for one Availability Zone, EFS is a
regional network file system that clients can share, and instance store is fast local scratch storage tied to
the host. Their failure and recovery behavior differ, so storage is part of the architecture, not just a size
field in the launch wizard.

- **EBS** is a persistent block device for one Availability Zone. A running EC2 instance can format and mount it like a disk.
- **EFS** is a regional NFS file system. Multiple instances can mount it at the same time when the network path and permissions are correct.
- **Instance store** is local scratch storage on the host. It is fast, but it is temporary.

The root EBS volume and an attached data volume are separate resources. A snapshot is separate again. Deleting the instance does not automatically mean every independently created volume or snapshot is gone.

Use EBS for a server's boot disk or application data that needs a block device. Use EFS when multiple Linux
clients need shared file access over the network. Use instance store only for data you can rebuild. Before
deleting an instance, inspect its termination behavior and list volumes and snapshots separately. A common
mistake is assuming "delete server" means "delete all storage"; independent volumes and recovery copies can
remain billable.

> **Figure.** Amazon EC2 Instances page showing a temporary t3 micro instance
>
> (1) The temporary instance is a t3.micro. Its Availability Zone matters because EBS volumes are zonal.

> **Figure.** Four kinds of storage. EBS: a block disk attached to one EC2 instance in one Availability Zone; it survives a reboot and a stop, and snapshots back it up to S3. EFS: a shared file system mounted over NFS by many instances across Availability Zones. S3: object storage reached over HTTPS from anywhere with permission, not mounted as a disk. Instance store: disks physically on the host, fast but lost when the instance stops or fails.
>
> Pick by who needs the data and whether it must survive: one server (EBS), many servers (EFS), any app (S3), scratch (instance store).

## EBS volume types

`gp3` is the normal starting point. It gives a general-purpose SSD baseline and lets you set IOPS and throughput independently. Use `io2` when the workload needs higher durability and sustained provisioned IOPS. `st1` is throughput-oriented HDD storage for large sequential workloads. `sc1` is the lowest-cost HDD option for infrequently accessed sequential data.

Do not choose `st1` or `sc1` for a database. Do not choose `io2` just because it sounds more enterprise. Measure latency, IOPS, throughput and the recovery requirement first.

The temporary lesson volume was a 1 GiB encrypted gp3 volume:

```text
{
    "VolumeId": "vol-0bae53dac6ff74161",
    "State": "creating",
    "Size": 1,
    "Type": "gp3",
    "Encrypted": true,
    "AZ": "ap-south-1b"
}
```

> **Figure.** Amazon EC2 Volumes page showing an encrypted one GiB gp3 volume
>
> (1) The lesson volume is gp3, 1 GiB and encrypted. The volume and instance must share an Availability Zone before attachment.

> **Video.** [Amazon EBS volume types: How to choose the right one(s) for your use case](https://www.youtube.com/watch?v=f3wp7ZGe2VU) (DoiT)

## Snapshots

An EBS snapshot is incremental after the first snapshot and is stored independently of the source volume. It is a recovery building block, not a complete backup policy. Test restoring a volume, protect snapshot permissions and define retention.

The captured snapshot was encrypted, linked to the 1 GiB volume and completed with no data blocks:

```text
{
    "SnapshotId": "snap-0ffc0b305cb37c638",
    "State": "pending",
    "Encrypted": true,
    "VolumeId": "vol-0bae53dac6ff74161",
    "Size": 1
}
```

> **Figure.** Amazon EC2 Snapshots page showing an encrypted snapshot of a one GiB volume
>
> (1) The snapshot row identifies the source volume and its one GiB size. Wait for completed before treating it as a recovery point.

> **Video.** [Introduction to Amazon EBS snapshot](https://www.youtube.com/watch?v=bDi1Sorxijo) (MotivaLogic Academy)

## Encryption

Without encryption, a copied disk or snapshot may expose data outside the running instance. EBS encryption protects
volume data at rest and snapshots derived from it, using a KMS key. New volumes can use the account's default
EBS encryption setting; teams may choose a customer-managed key when they need to control key policy, auditing
or cross-account sharing.

For a production system, decide who can use the key, who can create snapshots and who can copy them to another
Region. The lesson volume and snapshot used encryption at rest. Existing unencrypted data may require a snapshot
and copy workflow to encrypt it; enabling the account default affects new volumes, not every old volume.

Encryption does not grant access. IAM, KMS key policy, snapshot sharing and the instance's operating-system permissions still matter.

Use the default AWS-managed key when the built-in ownership and policy are sufficient. Use a customer-managed
key when a team must administer grants, rotation settings or access separately. Test restore permissions as
well as create permissions. A common mistake is removing a key policy or scheduling key deletion while
encrypted volumes or snapshots still depend on that key.

> **Video.** [EBS Volume Encryption - AWS SCS-C03](https://www.youtube.com/watch?v=fKKzYvK2gfM) (Cybr)

## EFS: a shared file system

EFS is regional, but clients connect through mount targets in VPC subnets. The file system can exist without a mount target, as it did in this lesson:

```text
{
    "FileSystemId": "fs-0ef4ae49937fb9368",
    "State": "creating",
    "Encrypted": true,
    "PerformanceMode": "generalPurpose",
    "ThroughputMode": "bursting",
    "MountTargets": 0
}
```

Create mount targets in the subnets where clients run, use security groups that allow NFS over TCP 2049, and mount with the recommended EFS helper. Mount targets are network resources with their own cost and should not be created casually in a teaching exercise.

> **Figure.** Amazon EFS File systems page showing an encrypted empty file system
>
> (1) The file system is encrypted and empty. It has no mount target because the lesson does not need a client network path.

> **Video.** [Amazon EFS file system creation, mounting & settings](https://www.youtube.com/watch?v=Aux37Nwe5nc) (Amazon Web Services)

## Instance store: temporary by design

Some EC2 types include an NVMe instance store device physically attached to the host. It can provide fast local
I/O without a separate network volume, but it is not a persistent recovery disk. Data may be lost when the
instance stops, hibernates, terminates or moves to replacement hardware; exact behavior depends on the instance
type and lifecycle event.

Use instance store for caches, temporary shuffle data or scratch processing that can be recreated. Keep the
source data on EBS, S3 or another durable system. Do not use it as the only copy of a database or user upload.
A common mistake is to confuse "local NVMe" with durable SSD storage; verify the instance's storage behavior
and make the workload tolerate its loss.

> **Video.** [EC2 Instance Store Explained](https://www.youtube.com/watch?v=0NBzlR9sm-E) (CloudWolf AWS)

## Tune gp3 for the workload

An EBS volume's capacity and performance affect both application behavior and cost. gp3 separates size from
provisioned IOPS (input/output operations per second) and throughput, so you can tune those settings without
choosing a larger volume just to get more performance. Start with the included baseline and measure actual
latency, queue depth and throughput before increasing them.

The CLI command below requests new IOPS and throughput values. EBS applies a modification asynchronously; the
second command checks its state and target values. Do not assume the change is complete as soon as the API
accepts the request.

```sh
$ aws ec2 modify-volume --volume-id "$VOLUME_ID" --iops 6000 --throughput 250
$ aws ec2 describe-volumes-modifications --volume-ids "$VOLUME_ID" \
  --query 'VolumesModifications[].{State:ModificationState,Progress:Progress,IOPS:TargetIops,Throughput:TargetThroughput}' --output table
```

Use gp3 as the general-purpose starting point. Consider io2 when measured I/O requirements and durability
needs justify its price. Increasing IOPS or throughput without evidence can raise cost without improving the
application. A common mistake is tuning the disk before checking whether the application, CPU or network is
the actual bottleneck.

## FSx is a specialised file system

Some applications require a file protocol or storage behavior that a general-purpose file system does not
provide. FSx is a family of managed file systems: Windows File Server supports SMB, Lustre targets high-throughput
compute, and NetApp ONTAP or OpenZFS provide their own storage features and operational semantics.

Choose a specific FSx system because the software or workload needs its protocol or performance model, not just
because an EBS volume is full. First compare the application's client support, latency, throughput, availability
and backup requirements. EFS is often simpler for shared Linux NFS access. A common mistake is treating FSx as
one interchangeable product; each file system has different deployment and pricing choices.

## DLM automates snapshot retention

Taking snapshots manually is easy to forget, and old snapshots can accumulate without a retention rule. Data
Lifecycle Manager (DLM) applies schedules to tagged EBS volumes or instances and creates snapshots on their
behalf. A policy can retain a defined number or age of recovery points, reducing manual work across a fleet.

The CLI command lists enabled policies. To use DLM, define the target tags, schedule, retention and execution
role, then verify the policy creates usable snapshots and removes only the intended old ones. AWS Backup is a
broader policy service for supported resources and cross-account recovery controls; DLM focuses on EBS
lifecycle automation.

```sh
$ aws dlm get-lifecycle-policies --state ENABLED --region ap-south-1 \
  --query 'Policies[].{Id:PolicyId,Description:Description,State:State}' --output table
```

Use DLM for repeatable EBS snapshot schedules based on tags. Use AWS Backup when a consistent central policy
must cover several AWS services. Neither tool proves your recovery process works: restore a snapshot into a
test environment and verify the data. A common mistake is setting retention without checking which tags match
or whether the retention period meets the system's recovery objectives.

> **Video.** [AWS Tutorial: Data Lifecycle Manager](https://www.youtube.com/watch?v=KBCaGqGhEwM) (CloudWolf AWS)

## AWS Backup

When each service has a separate backup schedule, teams can miss resources or apply inconsistent retention.
AWS Backup centralizes backup plans, schedules, lifecycle settings and recovery points for supported services.
It can apply policy across accounts and Regions when configured with the required permissions and vaults.

A plan selects resources through assignments, creates recovery points on a schedule, and applies retention rules.
The vault is where those recovery points are organized and protected. A hand-created EBS snapshot is still
useful for a one-off test, but it does not provide those governance controls by itself. Before adopting a plan,
check that each resource type and operation is supported in the target Region and account.

> **A snapshot is not a volume.** A snapshot does not become a mounted disk automatically. Restore it into a new EBS volume in the target Availability Zone, then attach and mount that volume with the correct operating-system steps.

> **In production.** Tag every volume and snapshot with owner, system and retention information. Encrypt by default. Use AWS Backup or an equivalent policy for important data, and regularly test restore instead of assuming a snapshot is usable.

> **Video.** [AWS Backup Restore testing Demo | Amazon Web Services](https://www.youtube.com/watch?v=IiXFN-ka_Ts) (Amazon Web Services)

Use AWS Backup when you need centrally governed backups across supported services and accounts. Use a one-off
snapshot for a controlled experiment, not as the only recovery plan for production. Test restores on a schedule,
measure how long they take, and confirm the restored application works. A common mistake is counting successful
backup jobs as proof of recoverability without ever restoring the data.

## Mission: Compare and clean up storage

Create a t3.micro, an encrypted gp3 volume, a snapshot and an encrypted EFS file system. Inspect their relationships, then remove every resource and verify that each identifier is gone.

- You need: AWS CLI credentials allowed to create and delete temporary EC2 and EFS resources
- You'll have: A verified storage inventory and a clean account with no lesson resources left behind

```sh
$ export AWS_REGION=ap-south-1
$ export AMI_ID="$(aws ec2 describe-images --owners amazon \
    --filters 'Name=name,Values=al2023-ami-2023.*-x86_64' 'Name=state,Values=available' \
    --query 'sort_by(Images,&CreationDate)[-1].ImageId' --output text)"
$ export INSTANCE_ID="$(aws ec2 run-instances --region "$AWS_REGION" --image-id "$AMI_ID" \
    --instance-type t3.micro --count 1 \
    --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=storage-types-mission}]' \
    --query 'Instances[0].InstanceId' --output text)"
$ export AZ="$(aws ec2 describe-instances --region "$AWS_REGION" --instance-ids "$INSTANCE_ID" \
    --query 'Reservations[0].Instances[0].Placement.AvailabilityZone' --output text)"
$ export VOLUME_ID="$(aws ec2 create-volume --region "$AWS_REGION" --availability-zone "$AZ" \
    --size 1 --volume-type gp3 --encrypted \
    --tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=storage-types-volume}]' \
    --query VolumeId --output text)"
$ aws ec2 wait volume-available --region "$AWS_REGION" --volume-ids "$VOLUME_ID"
$ export SNAPSHOT_ID="$(aws ec2 create-snapshot --region "$AWS_REGION" --volume-id "$VOLUME_ID" \
    --description storage-types-mission --query SnapshotId --output text)"
$ export FILE_SYSTEM_ID="$(aws efs create-file-system --region "$AWS_REGION" --encrypted \
    --performance-mode generalPurpose --throughput-mode bursting \
    --tags Key=Name,Value=storage-types-efs --query FileSystemId --output text)"
$ aws ec2 describe-volumes --region "$AWS_REGION" --volume-ids "$VOLUME_ID" \
    --query 'Volumes[0].{State:State,Type:VolumeType,Size:Size,Encrypted:Encrypted,AZ:AvailabilityZone}' --output table
---------------------------------------------
|              DescribeVolumes               |
+------------+------+-------+---------+------+
| Encrypted  | Size | State | Type    |  AZ  |
+------------+------+-------+---------+------+
|  True      |  1   | avail | gp3     |  AZ  |
+------------+------+-------+---------+------+
$ aws ec2 delete-snapshot --region "$AWS_REGION" --snapshot-id "$SNAPSHOT_ID"
$ aws ec2 delete-volume --region "$AWS_REGION" --volume-id "$VOLUME_ID"
$ aws efs delete-file-system --region "$AWS_REGION" --file-system-id "$FILE_SYSTEM_ID"
$ aws ec2 terminate-instances --region "$AWS_REGION" --instance-ids "$INSTANCE_ID"
$ aws ec2 wait instance-terminated --region "$AWS_REGION" --instance-ids "$INSTANCE_ID"
$ aws ec2 describe-volumes --region "$AWS_REGION" --volume-ids "$VOLUME_ID"
An error occurred (InvalidVolume.NotFound) when calling the DescribeVolumes operation
$ aws ec2 describe-snapshots --region "$AWS_REGION" --snapshot-ids "$SNAPSHOT_ID"
An error occurred (InvalidSnapshot.NotFound) when calling the DescribeSnapshots operation
$ aws efs describe-file-systems --region "$AWS_REGION" --file-system-id "$FILE_SYSTEM_ID"
An error occurred (FileSystemNotFound) when calling the DescribeFileSystems operation
```

The instance check should also return a terminated state before you finish. If you attach a volume in your own experiment, unmount it before deleting it.

## Try it

- Inspect the root disk and instance-store behavior for an EC2 instance.
- Create a small encrypted gp3 volume and inspect its IOPS and throughput.
- Create a snapshot and verify its source volume and encryption.
- Create an encrypted EFS file system without a mount target.
- Delete every temporary resource and verify each one is gone.

## Quiz

1. Which storage is a zonal block device that you attach to an EC2 instance?
   - **EBS** (answer)
   - EFS
   - Instance store only
   Why: EBS is a persistent block device in one Availability Zone. EFS is a shared file system, while instance store is physically attached temporary storage.

2. Which EBS class is the normal starting point for general-purpose workloads?
   - sc1
   - **gp3** (answer)
   - io2 Block Express for every workload
   Why: gp3 provides a balanced general-purpose baseline with independently configurable IOPS and throughput.

3. What does an EBS snapshot represent?
   - **A copy of an EBS volume that can be used to create another volume** (answer)
   - A running EC2 instance
   - A DNS record
   Why: A snapshot is a point-in-time backup of an EBS volume. It is stored separately and can seed a new volume.

4. What must exist before an EC2 instance in a VPC can mount EFS?
   - A Route 53 public domain
   - **An EFS mount target reachable from the instance subnet** (answer)
   - An S3 bucket policy
   Why: Mount targets provide the network endpoints through which clients access EFS in a VPC.

5. What is the important warning about instance store data?
   - It survives every stop and termination
   - It is shared across Regions
   - **It is temporary and can disappear when the instance stops or terminates** (answer)
   Why: Instance store is tied to the host. Use it for scratch data, caches or buffers, never as the only copy of important data.

## Resources

- [Amazon EBS User Guide](https://docs.aws.amazon.com/ebs/latest/userguide/what-is-ebs.html) (AWS Docs)
- [Amazon EBS volume types](https://docs.aws.amazon.com/ebs/latest/userguide/ebs-volume-types.html) (AWS Docs)
- [Amazon EFS User Guide](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html) (AWS Docs)
- [Amazon EC2 instance store](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html) (AWS Docs)
- [AWS Backup Developer Guide](https://docs.aws.amazon.com/aws-backup/latest/devguide/whatisbackup.html) (AWS Docs)
