> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-architect.ipoint-labs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Mount Elastic File system (EFS) on EC2

> Hands-on lab · 45m

Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console.

<a className="ip-lab-portal-btn" href="https://labs.intellectualpoint.com/labs/mount-elastic-file-system-efs-on-ec2" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab details

1. This lab walks you through the steps to create an Elastic File System.
2. You will launch and configure two Amazon EC2 Instances.
3. You will practice mounting the EFS to both instances by logging into each instance via SSH authentication.
4. You will practice sharing files between two instances.
5. Duration: **1 hour**
6. AWS Region: **US East (N. Virginia) us-east-1**

### Architecture diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/001.png?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=2aa358c853397d5d4aa0eaf08f97c903" alt="" width="1604" height="721" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/001.png" />

### Task details

1. Sign in to AWS Management Console
2. Launching 2 EC2 instances.
3. Create an Elastic File System.
4. Mount the file system to MyEC2-1 Instance
5. Mount the file system to MyEC2-2 Instance
6. Testing the file system
7. Validation of the lab.

### Launching the lab environment

1. To launch the lab environment, Click on the **Launch lab** button.
2. Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
3. Once the Lab is started, you will be provided with **IAM user name**, **Password**, **Access** **Key**, and **Secret** **Access** **Key**.

<Note>
  You can only start one lab at any given time
</Note>

## Lab guide

### Lab steps

#### Task 1: Sign in to AWS Management Console

1. Click on the **Open console** button, and you will get redirected to AWS Console in a new browser tab.
2. On the AWS sign-in page,

   * Leave the Account ID as default. Never edit/remove the 12 digit Account ID present in the AWS Console. otherwise, you cannot proceed with the lab.
   * Now copy your **User Name** and **Password** in the Lab Console to the **IAM Username and Password** in AWS Console and click on the **Sign in** button.
3. Once Signed In to the AWS Management Console, Make the default AWS Region as **US East (N. Virginia) us-east-1.**

<Note>
  If you face any issues, please go through [**FAQs and Troubleshooting**](/aws-cp/support/faqs-and-troubleshooting).
</Note>

#### Task 2: Launching two EC2 Instances

1. Make sure you are in the **N.Virginia** Region.

2. Navigate to the **Services** menu in the top, then click on **EC2** in the **Compute** section.

3. Click on **Instances** from the left side bar and then click on **Launch instances**.

4. Number of Instances :  Enter ***2*** on the right side under summary

5. Name : Enter ***MyEC2***

6. **For Amazon Machine Image (AMI):** Search for **Amazon Linux 2023 kernel-6.1 AMI** in the search box and click on the **Select** button.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/002.png?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=cb4e79e2ad7c9e48ec8d92b3b1a055af" alt="" width="930" height="466" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/002.png" />

7. **For Instance Type:** select ***t2.micro***

<img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/003.jpg?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=a46b69198bdc98f1c59b2c6b0e54bf2d" alt="" width="1887" height="465" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/003.jpg" />

8. For Key pair: Select **Create a new key pair** Button

   * Key pair name: **MyEC2Key**
   * Key pair type: **RSA**
   * Private key file format: **.pem**
9. Select **Create key pair** Button.
10. In Network Settings Click on **Edit**:

* Auto-assign public IP: **Enable**
* Select **Create new Security group**
* Security Group Name: Enter ***EFS Security Group***

  * To add **SSH:**

    1. Choose Type: **SSH**
    2. Source: **Anywhere**
  * For **NFS:**

    1. Click on **Add security group rule**
    2. Choose Type: **NFS**
    3. Source: **Anywhere**

11. Keep Rest thing Default and Click on **Launch Instance** Button.

12. Select **View all Instances** to View Instance you Created

13. **Launch Status:** Your instance is now launching. Click on the instance ID and wait until the initialization status changes to **Running.**

14. Click on each instance and enter a names as ***MyEC2-1*** and ***MyEC2-2**\_\_.*

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/004.jpg?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=d5111c9c3a5ba83986210cb121cc6645" alt="" width="2457" height="365" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/004.jpg" />

15. Take note of the IPv4 Public IP Addresses of the EC2 instances and save them for later.

#### Task 3: Creating an Elastic File System

1. Navigate to **EFS** by clicking on the **Services** menu at the top. Click on **EFS** in the  **Storage** section.
2. Click on **Create file system**
3. Click on **Customize** button.
4. Enter the details below, Type the **Name** as ***EFS-Demo*** and make sure **default** **VPC** and **default Regional** options are selected.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/005.jpg?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=09f300844a9df1341bcb0ca248d0156a" alt="" width="1573" height="699" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/005.jpg" />
5. Uncheck the option of **Enable automated backups**
6. Leave everything by default and click on the **Next** button present below.
7. **Network Access**:

* **VPC**

  * An Amazon EFS file system is accessed by EC2 instances running inside one of your VPCs.
  * Choose the same VPC you selected while launching the EC2 instance (leave as default).
* **Mount Targets**

  * Instances connect to a file system by using a network interface called a mount target. Each mount target has an IP address, which we assign automatically or you can specify.
  * We will select **all the Availability Zones** (AZ’s) so that the EC2 instances across your VPC can access the file system.
  * Select **all the Availability Zones**, and in the Security Groups, select **EFS Security Group** instead of the default value.
  * Scroll down to '**Mount Targets**', then click on '**Add Mount Target'**. Select the availability zone and change the security group to **EFS Security Group.**
  * Make sure you remove the default security group and select the EFS Security Group, otherwise you will get an error in further steps.
  * Click on **Next** button

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/006.png?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=7441933682d120d80841f48740e9ebfd" alt="" width="1005" height="556" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/006.png" />

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/007.png?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=487f594c8c04d6fd36a04fa77c443955" alt="" width="1140" height="651" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/007.png" />

8. **File system policy - optional** let it be optional only. Click on **Next** button
9. **Review and Create**: Review the configuration below before proceeding to create your file system. Click on **Create** button.
10. Congratulations on creating the EFS File system, It's time to **mount** your EC2 Instance with the EFS File system.

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/008.jpg?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=d99dcde158755503b13f2f16dd44ae5b" alt="" width="2317" height="958" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/008.jpg" />

#### Task 4: Mount the File System to MyEC2-1 Instance

1. Select the MyEC2-1 Instance and copy the IPv4 Public IP.
2. SSH into the EC2 Instance

* Please follow the steps in [SSH into EC2 Instance](/aws-cp/support/ssh-into-ec2-instance).

3. Switch to root user

   ```
   sudo -s
   ```
4. Run the updates using the following command:

   ```
   yum -y update
   ```
5. Install the NFS client as amazon-efs-utils.

   ```
   yum install -y amazon-efs-utils
   ```
6. Create a directory by the name **efs**

   ```
   mkdir efs
   ```
7. We have to mount the file system in this directory.
8. To do so, navigate to the AWS console and click on the created file system. On the top-right corner, click on **Attach**

* Copy the command of **Using the EFS mount helper.**

  ```
  sudo mount -t efs -o tls <dns name of EFS>:/ efs
  ```
* **Note**: **Replace \<dns name of EFS> with the DNS of the Elastic File System you've created.**

9. To display information for all currently-mounted file systems, we'll use the command bellow:

   ```
   df -h
   ```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/009.png?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=a5ab49c7c3691116e70b058b5c04cfed" alt="" width="1160" height="226" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/009.png" />

10. Create a directory in our current location:

    ```
    mkdir aws
    ```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/010.jpg?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=1c4313e80e91863fda200a3f89a74aa4" alt="" width="803" height="153" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/010.jpg" />

#### Task 5: Mount the File System to MyEC2-2 Instance

1. Select the MyEC2-2 Instance and copy the IPv4 Public IP.
2. SSH into the EC2 Instance

* Please follow the steps in [SSH into EC2 Instance](/aws-cp/support/ssh-into-ec2-instance).

3. Switch to root user

   ```
   sudo -s
   ```
4. Run the updates using the following command:

   ```
   yum -y update
   ```
5. Install the NFS client as amazon-efs-utils.

   ```
   yum -y install amazon-efs-utils
   ```
6. Create a directory with the name **efs**

   ```
   mkdir efs
   ```
7. We have to mount the file system in this directory.
8. To do so, navigate to the AWS console and click on the created file system. On the top-right corner, click on **Attach**

* Copy the command of **Using the EFS mount helper.**

  ```
  sudo mount -t efs -o tls <dns name of EFS>:/ efs
  ```

  **Note: Replace \<dns name of EFS> with the DNS of the Elastic File System you've created.**
* To display information for all currently mounted file systems, we'll use the command

```
df -h
```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/011.png?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=690a92c879048177363231038d47762e" alt="" width="1152" height="246" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/011.png" />

#### Task 6: Testing the File System

1. SSH into both instances in a side-by-side view on your machine, if possible.
2. Switch to root user

   ```
   sudo -s
   ```
3. Navigate to the **efs directory in both the servers** using the command

   ```
   cd efs
   ```
4. Create a file in any one server.

   ```
   touch hello.txt
   ```
5. Check the file using the command

   ```
   ls -ltr
   ```
6. Now go to the other server and give the command

   ```
   cd efs
   ```
7. You can see the file created on this server as well. This proves that our EFS is working.
8. You can try creating files (**touch** command) or directories (**mkdir** command) on other servers to continue to grow the EFS implementation.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/012.png?fit=max&auto=format&n=sjxZZnuQfFzzjiqS&q=85&s=d2c56ed0898f97884914569b64364233" alt="" width="1325" height="419" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/012.png" />

<Tip>
  **Do you know?**

  EFS uses the Network File System (NFS) protocol, which enables EC2 instances to mount EFS as a network file system, providing a common data source for applications running on multiple instances.
</Tip>

#### Task 7: Validation Test

1. Once the lab steps are completed, please click on the **Check my work** button on the left side panel.
2. This will validate the resources in the AWS account and displays whether you have completed this lab successfully or not.
3. Sample output :

<img src="https://mintcdn.com/ip-cloud-architect-pathway/sjxZZnuQfFzzjiqS/images/labs/mount-elastic-file-system-efs-on-ec2/013.gif?s=4d5d16e6a0af09141b717345e28003ba" alt="" width="1000" height="597" data-path="images/labs/mount-elastic-file-system-efs-on-ec2/013.gif" />

### Completion and conclusion

1. You have successfully created an Elastic File System.
2. You have successfully created 2 Amazon Linux instances.
3. You have successfully installed the NFS Client and mounted EFS to the instances.
4. You have successfully tested the file-share between both Instances.

### End lab

1. Sign out of AWS Account.
2. You have successfully completed the lab.
3. Once you have completed the steps, click on **End lab** in the IP Lab Portal.

## What gets checked

When you press **Check my work**, the platform verifies each of these:

* **Launch an EC2 Instance** — Check whether an EC2 Instance is launched or not.
* **Launch EC2 AMI type Amazon Linux** — Check whether the EC2 instance is launched using an Amazon AMI.
* **Create Elastic File system** — Check whether Elastic File system is created or not.

## Related help

* [FAQs and Troubleshooting](/aws-cp/support/faqs-and-troubleshooting)
* [SSH into EC2 Instance](/aws-cp/support/ssh-into-ec2-instance)
