Create and mount an Amazon EFS file system

using Amazon EC2 Launch Instance Wizard

In this tutorial, you learn how to mount an Amazon Elastic File System (Amazon EFS) file system to an Amazon Elastic Compute Cloud (Amazon EC2) instance using the EC2 Launch Instance Wizard. The Launch Instance Wizard specifies all the launch parameters required for launching an instance. Where the launch instance wizard provides a default value, you can accept the default or specify your own value. This integration simplifies and eases the process of mounting Amazon EFS file systems to Amazon EC2 instances at launch time with recommended mount options.

In this tutorial, you first create a new file system, then mount it to a new EC2 instance at the launch using the wizard, verify that file system is mounted on the EC2 instance, and then delete resources created in this tutorial. To learn more, see the Launch Instance Wizard documentation and the Amazon EFS documentation.

This tutorial is AWS Free Tier eligible.

About this Tutorial
Time 10 minutes      
Cost Less than $1
Use Case Compute
Products Amazon EFS, Amazon EC2
Audience Developers
Level Intermediate
Last Updated July 21, 2020

Step 1: Create the security groups

For this step, you create two security groups - one that is attached to the Amazon EC2 instance and one that is attached to the Amazon EFS file system.

1.1 — Open the Amazon VPC dashboard and sign in with your AWS account credentials. If you do not have an AWS account, create a new AWS account to get started.

Already have an account? Log in to your account

1.2 — Choose the Region drop-down and select the AWS Region where you want to create the Amazon EFS file system and launch your Amazon EC2 instance. This tutorial uses the US West (Oregon) Region.

1.3 — In the left navigation pane, choose Security Groups. There will be a default security group listed. Create the following two additional security groups in the default VPC. For detailed steps, see Creating a Security Group.

  • EC2-sg: This security group will be attached to the EC2 instance and it allows only SSH connection inbound to the EC2 instance and any outbound connectivity.
  • EFS-sg: This security group will be attached to the EFS file system and allows only TCP connection on port 2409 from the EC2 instance and any outbound connectivity.

Alternatively, modify your existing security groups to ensure that only your EC2 instance can connect to your Amazon EFS file system on the Network File System (NFS) port. For more information on minimal permissions for EFS access, see Controlling Network Access.

1.4 – Select the EC2-sg security group and choose the Inbound Rules tab. Verify that the Type is SSH. Then, choose the Outbound Rules tab and verify that the Type is All traffic.

1.5 — Select the EFS-sg security group and choose the Inbound Rules tab. Verify that the Source is security group EC2-sg. Then, choose the Outbound Rules tab and verify that the Type is All traffic.

Step 2: Create the EFS file system

In this step, you use Amazon Elastic File System (Amazon EFS) to create the file system.

2.1 — Navigate to Amazon EFS in the AWS Management Console and choose Create file system.

2.2 – On the Configure network access page, do the following:

  1. For VPC, choose your default VPC.
  2. For mount targets, select the check boxes for all of the Availability Zones in this Region. Make sure all mount targets use the default subnets and Automatic IP addresses.
  3. In the Security groups column, delete the existing security groups and add the EFS-sg security group.
  4. Choose Next Step.
 

2.3 – On the Configure file system settings page, for Throughput mode, choose Bursting. For Performance mode, choose General Purpose. Leave the default values for all other settings and choose Next Step.

2.4 – On the Configure client access page, choose Next Step. (You do not need to configure client access for this tutorial.)

2.5 – On the Review and create page, review the file system configuration and choose Create File System.

On the File systems page, note the File system ID of your new file system. In the Mount targets section, the initial state is Creating, which changes to Available when ready. Now, your file system is ready to be mounted to Amazon EC2 instances and on-premises instances!

Step 3: Launch the EC2 instance and mount the file system

In this step, you use the launch wizard to launch an Amazon EC2 instance and then mount the file system to the EC2 instance. Before you can launch and connect to an Amazon EC2 instance, you need to create a key pair, you can also use your existing key pair for this exercise. For more information, see Creating a key pair using Amazon EC2.

3.1 — Navigate to the Amazon EC2 console and choose Launch Instance.

3.2 – On the Choose an Amazon Machine Image (AMI) page, select the Amazon Linux 2 AMI.  

3.3 – On the Choose an Instance Type page, select t2.micro. Then, choose Next: Configure Instance Details.

3.4 – On the Configure Instance Details page, do the following:

  • For Network, choose the default VPC.
  • For Subnet, choose No preference.
  • For File systems, choose Add file system and select the file system ID from Step 2. The path shown next to the file system ID is the location at which the file system will be mounted on the EC2 instance. You can customize this path, but for this tutorial, keep the default value.

Note: After you select the file system ID, the User data field is automatically populated with a configuration script that automates all manual tasks, such as installing the file system client, installing the EFS mount helper (for Amazon Linux only), and updating the EC2 instance properties so that the file system mounts automatically upon instance reboot.

  • Leave all other settings as the default values.

Choose Next: Add Storage.

3.5 – On the Add Storage page, keep the default storage settings and choose Next: Add Tags.

3.6 – On the Add Tags page, choose Next: Configure Security Group. (You do not need to add tags for this tutorial.)

3.7 – On the Configure Security Group page, for Assign a security group, choose Select an existing security group. Then, choose the EC2-sg security group and choose Review and Launch.

3.8 – Review the EC2 instance details and choose Launch.

3.9 – In the key pair dialog box that appears, select Choose an existing key pair and then select an appropriate key pair. Select the I acknowledge check box and then choose Launch Instances.  

3.10 – On the Launch Status page, choose View Instances to open the Instances dashboard.

On the Instances dashboard, you will see the new EC2 instance is created and running. You can give a name to the EC2 instance. Select the EC2 instance and view the additional details about it such as Public IP and DNS hostname, VPC ID, Private IP, Availability Zone and other information.

 

Step 4: Verify EFS file system is mounted

In this step, you connect to your Amazon EC2 instance and verify that the Amazon EFS file system is mounted.

4.1 — Navigate to the EC2 console. In the EC2 navigation pane, choose Instances, then select the EC2 instance you created in Step 3. Choose Connect.

4.2 — In the Connect to your instance dialog box, choose EC2 Instance Connect (browser-based SSH connection) and then choose Connect.

4.3 — In the EC2 instance CLI, type the following command:

df -T -h

You can see that the EFS File System is mounted at mnt/efs/fs1 which is the same default path as mentioned in Step 3.4. This verifies that your file system is successfully mounted on the EC2 instance.

Step 5: Clean up

In the following steps, you clean up the resources you created in this tutorial.

It is a best practice to delete instances and resources that you are no longer using so that you are not continually charged for them.  

Terminate EC2 instance

5.1 — Open the Amazon EC2 console.

5.2 — In the navigation pane, choose Instances.

5.3 — Select the instance you created for this tutorial, and choose Actions, Instance State, Terminate.

5.4 — Choose Yes, Terminate when prompted for confirmation.

Note: This process can take several seconds to complete. Once your instance has been terminated, the Instance State will change to terminated on your EC2 Console.

Delete EFS file system

5.5 — Open the Amazon EFS console.

5.6 — On the File systems page, select the file system you created for this tutorial.

5.7 — Choose Delete.

5.8 — In the Delete file system dialog box, enter the file system ID shown, and choose Confirm to confirm the delete.

Congratulations

You have created and mounted an Amazon EFS file system to a Amazon EC2 instance using the EC2 launch instance wizard!

Was this tutorial helpful?

Thank you
Please let us know what you liked.
Sorry to disappoint you
Is something out-of-date, confusing or inaccurate? Please help us improve this tutorial by providing feedback.

Learn more about Amazon EFS features

Find out more about the features of Amazon EFS with the Amazon EFS User Guide.

Dive deeper into Amazon EFS resources

Find valuable resources to help you get the most out of your Amazon EFS deployment.

Learn more about Amazon EC2 Launch Instance wizard

Find out more about the Launch Instance wizard in the Amazon EC2 documentation.