# AWS EBS Multi-Attach

### What is EBS Multi-Attach?

Amazon EBS Multi-Attach enables you to attach a single Provisioned IOPS SSD (io1 or io2) volume to multiple instances that are in the same Availability Zone. You can attach multiple Multi-Attach enabled volumes to an instance or set of instances. Each instance to which the volume is attached has full read and write permission to the shared volume. Multi-Attach makes it easier for you to achieve higher application availability in clustered Linux applications that manage concurrent write operations.

### Limitations of EBS Multi-Attach:

There are a few limitations to be aware of when using Amazon Elastic Block Store (EBS) Multi-Attach volumes:

* Only Nitro-based EC2 instances can use Multi-Attach volumes. This means that instances launched from certain older instance types or virtualization types will not be able to use Multi-Attach volumes
    
* Multi-Attach volumes can only be attached to instances in the same availability zone. This means that you cannot use Multi-Attach to share a volume across multiple availability zones
    
* Multi-Attach volumes can only be attached to instances that are in the running or stopped state. You cannot attach a Multi-Attach volume to an instance that is in the terminated state
    
* Only certain types of workloads are suitable for Multi-Attach. High-performance workloads such as databases, big data, and HPC could be designed to use Multi-attach
    
* Multi-Attach volumes can only be used with provisioned IOPS SSD (io1) and General Purpose SSD (gp2) volumes, and not with magnetic (standard) volumes
    
* Multi-Attach volumes are currently only available in certain regions
    
* The maximum IOPS and throughput limits per volume are lower when using Multi-Attach compared to when using a single-attach volume
    

### Hands-on Lab Overview

The aim of this hands-on lab is to create EBS Multi-Attach and see it in action. We will create two EC2 instances (`FirstInstance` and `SecondInstance`) and one EBS volume with Multi-Attach enabled functionality. This EBS volume will be attached to the two EC2 instances. By accessing this EBS volume from one EC2 machine, we will format it, mount and create a file `demoFile`. We will access this file from the second EC2 machine. Then, we will create a file `secondDemoFile` on the second EC2 instance and access it from the first EC2 instance.

### Hands-on Lab

1. Create an SSH key pair:
    
    ![](https://i.imgur.com/zbLxlZN.png align="center")
    
2. Create two EC2 instances with different AMIs: one with Ubuntu (AMI ID: ami-053b0d53c279acc90) and the second with Linux 2 (AMI ID: ami-09538990a0c4fe9be). Choose the instance type `t3.small` for both EC2 machines.
    
    ![](https://i.imgur.com/ZVbPnNX.png align="center")
    
3. Then, create an EBS Multi-Attach volume:
    
    ![](https://i.imgur.com/wpIkx41.png align="center")
    
4. Attach EBS Multi-Attach Volume to the two EC2 instances:
    
    ![](https://i.imgur.com/fpkpuSO.png align="center")
    
5. Check whether the volume was attached to the two EC2 instances:
    
    ![](https://i.imgur.com/GqyXhht.png align="center")
    
6. Connect to the first EC2 instance above (`FirstInstance`) running Ubuntu via AWS EC2 Connect.
    

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">IMPORTANT: Not all AMIs provided by AWS have EC2 Instance Connect integrated by default. The Amazon Linux 2 AMI and Ubuntu 20.04 or later come pre-configured with EC2 Instance Connect.</div>
</div>

7. When the connection is established, list all available block devices on the instance to identify the block device that corresponds to your EBS volume:
    
    ```bash
    lsblk
    ```
    
8. As we can see as a result of `lsblk` command, there is no mount point for the attached EBS volume.
    
    ![](https://i.imgur.com/XjbQlXG.png align="center")
    
9. Format the EBS Volume:
    
    ```bash
    sudo mkfs.ext4 /dev/nvme1n1
    ```
    
10. Mount the EBS Volume:
    
    Now, create a directory where you'll mount the volume:
    
    ```bash
    sudo mkdir /mnt/myvolume
    ```
    
    Mount the volume to this directory:
    
    ```bash
    sudo mount /dev/nvme1n1 /mnt/myvolume
    ```
    
    ![](https://i.imgur.com/Mhcbb8w.png align="center")
    
11. Connect to the second EC2 instance and identify the block device that corresponds to your EBS volume with the command `lsblk`.
    
12. Mount the EBS Volume:
    
    Now, create a directory where you'll mount the volume and mount the volume to this directory:
    
    ![](https://i.imgur.com/e4Naw8e.png align="center")
    
13. Access the `demoFile` from the second EC2 instance:
    
    ![](https://i.imgur.com/YH8qHTN.png align="center")
    
14. Create another file `secondDemoFile` on the second EC2 instance:
    
    ![](https://i.imgur.com/1Kf0qS7.png align="center")
    
15. Finally, to access `secondDemoFile` from the first EC2 instance, first, we need to unmount the EBS volume and mount it again to see the changes made by other instances.
    
    ![](https://i.imgur.com/UhQgh6D.png align="center")
    

### References

1. [AWS for Beginners: How to Enable Multi-Attach for Amazon EBS Volumes: Part 17](https://www.bdrsuite.com/blog/aws-for-beginners-a-guide-to-enable-multi-attach-for-ebs-volumes-part-17/#:~:text=There%20are%20a%20few%20limitations,to%20use%20Multi%2DAttach%20volumes)
    
2. [Install EC2 Instance Connect](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-connect-prerequisites.html#eic-prereqs-amis)
