Create and mount an Amazon EFS file system
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|
|Cost||Less than $1|
|Products||Amazon EFS, Amazon EC2
|Last Updated||July 21, 2020|
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.
2.2 – On the Configure network access page, do the following:
- For VPC, choose your default VPC.
- 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.
- In the Security groups column, delete the existing security groups and add the EFS-sg security group.
- 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!
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.
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.
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.
You have created and mounted an Amazon EFS file system to a Amazon EC2 instance using the EC2 launch instance wizard!
Recommended next steps
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.