Amazon EFS is a scalable, fully managed elastic file storage service designed for AWS cloud applications. It provides a straightforward way to add and share file storage across multiple EC2 instances, perfect for high-availability applications. With EFS, you can use standard mount points or leverage access points to create unique entry points with managed permissions.
This guide will walk you through mounting Amazon Elastic File System (EFS) access points on an EC2 instance. We’ll cover both temporary mounting methods and the steps to make the mount permanent using the fstab
file.
Prerequisites
To proceed, ensure you have:
- An Amazon EFS file system in your AWS region.
- A configured EC2 instance with access to the EFS file system’s security group.
- AWS CLI is installed and properly configured on your EC2 instance.
Option 1: Temporarily Mounting the EFS Access Point
A temporary mount is great for testing or when you don’t need the mount to persist across reboots.
1. Install the Amazon EFS Utilities (if not already installed):
sudo yum install -y amazon-efs-utils
Tip: If you are having issues with installing the amazon-efs-utils
helper packager, refer to this documentation on AWS for installation and troubleshooting steps.
2. Create a Directory for Mounting: You’ll need a directory to serve as the mount target. For example, /demo/efs
.
sudo mkdir -p /demo/efs
3. Identify the EFS Access Point ID: Find your EFS volume handle and access point ID in the AWS Console. You can find your accesspoint ID under Amazon EFS > Access Points.
4. Mount the EFS File System: Run the following command, substituting fs-12345678
with your EFS file system ID and ap-12345678
with your access point ID:
Mount the EFS Volume:
sudo mount -t efs -o tls fs-12345678:/ /demo/efs
To mount an EFS access point:
sudo mount -t efs -o tls,accesspoint=ap-12345678 fs-12345678:/ /demo/efs
Here:
-t efs
specifies the EFS type.-o tls
enables encryption in transit.accesspoint=ap-12345678
designates the specific EFS access point.
5. Verify the Mount: Check that the file system is mounted correctly by listing the contents of /mnt/efs
:
ls /demo/efs
This mount will only persist for your current session. Once the EC2 instance reboots, you’ll need to remount it. To make this mount permanent, continue with Option 2.
Permanently Mounting the EFS Access Point with fstab
To make the mount persist across reboots, configure the file system in /etc/fstab
.
1. Edit the fstab File: Open /etc/fstab
in your preferred text editor
sudo nano /etc/fstab
2. Add an Entry for the EFS File System: Add the following line, updating it with your EFS file system ID and access point ID:
Note: You need to make sure that the directory where you want to mount the volume exists. Example: /data/efs
To mount the EFS Volume, add this enter:
fs-12345678:/ /demo/efs efs _netdev,tls 0 0
To mount the accesspoint, add this entry:
fs-12345678:/ /demo/efs efs _netdev,tls,accesspoint=ap-12345678 0 0
Here’s a breakdown:
fs-12345678:/
is the EFS file system./mnt/efs
is the mount target.efs
is the file system type._netdev
delays mounting until network resources are available (important for boot-up).tls
secures the connection with encryption in transit.
3. Test the fstab
Entry: Run the following command to apply the new mount without rebooting:
sudo mount -a
4. Confirm the Permanent Mount: Verify that the mount is listed with this command:
df -h
You should see your EFS file system mounted to /mnt/efs
, indicating it’s successfully configured for automatic mounting on reboot.
Troubleshooting Common Issues
If you encounter issues, here are some common solutions:
- Access Denied: Ensure the EFS access point and file system are in the same VPC and subnet as your EC2 instance.
- Security Groups: Confirm that your EC2 instance’s security group allows inbound traffic on port 2049 (NFS).
- Incorrect Access Point ID: Double-check that the access point ID in your mount command or
fstab
entry matches the one listed in the AWS Console.