EC2 Instance Storage

Mahedi Hasan Jisan
6 min readJul 3, 2021

Elastic Block Store (EBS):

We can use the data of an instance even if we terminate it. That being said, you will need another instance to mount the data but it has to be one instance at a time at the Certified Cloud Practitioner (CCP) level. In terms of Associate levels which are Solutions Architect, Developer, and SysOps, multi-attach is possible for some EBS. Also, another important thing is, EBS is bound to a specific availability zone.

What do you think so far? Is it a network drive or a physical drive?

It’s a network drive! which means that it is using network to talk to the instance and there should be some kind of latency! You can detach the EBS from one instance and use it to another instance quickly.

EBS- Delete on Termination?

If you want to use the storage to another instance then when you delete your instance, don’t delete the storage. While you are creating the EBS, you will see an option that says “Delete on Termination” and it will be off by default. However, for root EBL, it will be always on by default.

An Example!

Now, let’s go for some examples. We created an instance in the last article. Given below:

Instance Storage(root EBS and Terminate ON)

We want to create an EBS and attach it to this instance. That being said, the EBS needs to be in the same region, which is “ca-central-1a”! Alright, let’s create it.

Creating EBS and attached it to instance!

In the above example, we have created the EBS in the same region and attached it to the instance. Now, let’s check if we create an EBS in a different region and can use it in the same instance in the above example.

Different region instances and EBS!

Looks like, the statement is true that you can not use an EBS if the region is not the same as the instance that is available.

Now, Try deleting the instance and observe which EBS is still available?

EBS Snapshot:

We can make a copy of the EBS to a different region or AZ and use it there. It is however recommended to do the snapshot after detaching the EBS from the instance. Let’s create a snapshot of an EBS and we will see that we can then copy it to another region.

Snapshot created and the right image shows that you can copy it to another region!

Now, let’s create a volume and restore the content of the EBS to another region.

Creating Volume to another region!

AMI again?

AMI is a customization of an instance. AMI is created for a specific region but can be copied to another region. AMI can be customized to configure your software, operating system, etc. Also, you can create your own AMI and maintain it to create multiple instances. Therefore, the process is that you create an instance in a region. Then you customize it to make an AMI and use it to launch that instance into another region.

How do we create an AMI from an Instance?

Creating AMI of an Instance!

In the above example, we created an AMI from the selected instance. From the right side, you can see that the root EBS is created by snapshot! Cool, right?

How do we create an instance from that AMI?

Creating Instance from AMI

Follow the rest of the steps as before! Also remember, in the case of user code, you don’t have to re-install everything as you already did in the previous instance. Just use the “#!/bin/bash” line and a message.

Did your new instance from the AMI works? Hint: Try using the public IP address to see the message you set in the user code!

Something like this, right?

EBS Volume Type:

  • In the case of boot volumes, you can only use gp2/gp3 and io1/io2
  • gp2/gp3- General purpose SSD volumes that balance the price and performances for a wide range of workloads.
  • io1/io2- Highest performance SSD for low latency or high throughput workloads.
  • Also, check the documentation for EBS volumes types!

EBS multi-attach (for Io1 and Io2 only), You can use one EBS for multiple instances in the same region! Each instance will have full access to write and read to the volume.

Elastic File System (EFS):

It manages a network file system that can be mounted on EC2. EFS works with EC2 in multiple AZ. Highly available, scalable, and expensive.

  • Use Cases: Content Management, File Sharing, Web Serving, and WordPress, etc.
  • NFSv4.1 Protocol
  • Use a security group to control the NFS
  • It is compatible with Linux based AMI (not windows)
  • Encryption at rest using KMS

Let’s create an EFS:

EFS is created in three different zones with a security group!

To create it, go to the EFS section and create a file system. Keep everything default but go ahead create a separate security group for that EFS. After everything is done, you will see something like the above.

Now we need EC2 instances to use EFS! go ahead and create them!

If you are successful, then it is a shared file system. If you create a text file on one ec2 instance then you will be able to see another ec2 instance that shares the same EFS!

EFS!

EBS vs EFS

EBS can be attached to only one instance at a time! Locked to one AZ. gp2:IO increases if the disk size increases and can also increase IO independently. To migrate EBS volume across AZ then take a snapshot and restore the snapshot to another AZ. Root EBS volumes get terminated when the instance is terminated!

EFS can be mount to instances across different AZ. EFS shares website files and only for Linux instances. Pay per use!

That’s it for today! Cheers! 😃

--

--