Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

Mount Amazon EFS on EC2 Step by Step

Hands-on: create EFS in ap-south-1, open NFS from an EC2 security group, mount with the Amazon EFS mount helper, write a file, and clean up.

In this chapter

  • Create EFS and mount targets
  • Security group for port 2049
  • Mount on Amazon Linux 2023
  • fstab note and full cleanup

Cost

EFS storage is billed while the file system exists. Delete it after the lab. Stop or terminate the EC2 if you created one only for this lab.

Everyday example first: understand the lab

Two synthetic class web servers need the same shared handout folder. A file saved only on serverA local disk will not become serverB file just because both use the path /mnt/efs. Each client must actually mount the same EFS file system at its local directory, and the application user must have permission to use it. The lab below demonstrates that attachment; it does not require uploading real student documents.

Common errors and fixes

These are synthetic practice situations. Diagnose the signal before changing a resource; no infrastructure changes are needed to read this guide.

The mount waits and then times out.

A timeout suggests a reachability problem, not necessarily a file-ownership problem. Check the intended mount target, its Availability Zone and VPC relationship, and NFS access from the EC2 security group to the target on TCP2049. Read the exact error before changing anything. Making NFS reachable from the whole internet is not a diagnostic fix.

The file-system name cannot be resolved.

Check VPC DNS settings and whether the expected mount target exists and is available for the client location. Immediately after target creation, DNS records can take time to propagate. A name-resolution error occurs before ordinary file read/write permissions are evaluated. Changing directory ownership cannot repair missing DNS resolution.

The mount works, but the application cannot create a file.

EFS applies Unix numeric UID/GID and file-mode permissions. A root-owned test created with sudo does not prove that the nonroot application user can write. Compare the actual application identity with the directory owner and allowed operations. Plan appropriate ownership or an access point rather than making every directory writable by everyone.

Practical FAQ: decisions during real work

Does the tls option authorize every file operation?

No. TLS protects traffic in transit. Network access, any applicable IAM/file-system policy and POSIX file permissions are separate checks. A secure transport does not make a user the owner of all files. Distinguish an encrypted connection from permission to mount or modify a particular path.

Two applications can reach the same EFS mount target but use different access points. Give each application its own access-point root directory and, if needed, an enforced numeric POSIX identity. Restrict the allowed access point in IAM. The mount target still supplies network access, while the access point defines the application’s file-system view.

Why should I verify the mount before writing a test file?

The local mount directory can still exist when EFS is not mounted. Writing there in that state creates a local EC2 file, not shared EFS data. Inspect the actual mount associated with the intended path before interpreting a successful write. A directory name alone is not evidence that remote storage is attached.

What does a busy unmount mean?

A process may still have an open file or its working directory under the mount. Identify and finish the intended activity before a normal unmount. Do not force an unmount merely to make a lab result appear clean; that can interrupt active reads or writes. Closing the terminal view is not proof that every application stopped using the file system.

1. Lab: click by click

Region ap-south-1. You need an Amazon Linux 2023 EC2 in a VPC with DNS hostnames enabled (default VPC is fine).

A. Security groups

  1. Create SG efs-lab-sg for EFS. Inbound: NFS TCP 2049 from the EC2 security group (source = EC2 SG id). Outbound: all.
  2. On the EC2 SG: allow SSH from My IP (if you use SSH). Outbound all is enough for mount.

B. Create EFS

  1. Console → EFS → Create file system.
  2. Name: lab-efs. VPC: same as EC2. Customize if needed — one mount target per AZ used by your subnet.
  3. Attach security group efs-lab-sg to mount targets (replace default if it is too open).
  4. Create. Wait until Available. Copy File system ID fs-.........

C. Install mount helper on EC2

Use the file-system ID from the EFS console to identify the storage you intend to mount. The mount helper accepts that ID and can use TLS, which protects the connection in transit. Run it from the lab EC2 instance whose network can reach the target. Keep the helper installation, mount target setup and permissions as separate checks so one successful step does not hide a later failure.

After mounting, create one small test file using the same local account as the intended app. If the write fails, inspect the mounted directory’s owner and group and compare them with id for that account. If it works, read the same filename from a second approved mount. If you later try the persistent mount entry, test it without rebooting first and know how to restore the previous configuration. This is how you avoid a boot failure caused by a mistaken remote mount entry.

  1. SSH to EC2 (or EC2 Instance Connect).
  2. Install:
sudo dnf install -y amazon-efs-utils
# Amazon Linux 2: sudo yum install -y amazon-efs-utils

D. Mount

Mounting makes a file system available at a directory on Linux. The directory can exist before a mount is attached. If the command fails and you write a test file anyway, the file can go to the local disk. Use findmnt --mountpoint /mnt/efs with the actual mount path to show that the directory is a mount point before saving the practice file.

Trace the request from EC2 to the EFS mount target, an address in the VPC that accepts the NFS file protocol. The network path and security rules must allow the connection. Once mounted, check file ownership as the real application user. If a second authorized instance mounts the same file system, a file written by the first should be visible to it. If the second cannot even mount, inspect the network and DNS before editing ownership.

  1. Make mount point and mount (replace FILE_SYSTEM_ID):
sudo mkdir -p /mnt/efs
sudo mount -t efs -o tls FILE_SYSTEM_ID:/ /mnt/efs
echo "hello from $(hostname)" | sudo tee /mnt/efs/hello.txt
cat /mnt/efs/hello.txt
df -hT | grep efs

Expected: file content prints; df shows type nfs4 or efs.

E. Optional fstab

  1. For reboot persistence (lab optional):
echo "FILE_SYSTEM_ID:/ /mnt/efs efs _netdev,tls 0 0" | sudo tee -a /etc/fstab
sudo umount /mnt/efs && sudo mount -a
df -hT | grep efs

Cleanup

  1. sudo umount /mnt/efs — remove fstab line if added.
  2. EFS console → Delete file system lab-efs (confirm).
  3. Delete efs-lab-sg if unused. Stop/terminate lab EC2.

2. Interview angles

Q. Which port?

TCP 2049 (NFS).

Q. Why source SG not 0.0.0.0/0?

Least privilege — only EC2 SG can mount.

Q. tls mount option?

Encrypts NFS in transit.

Q. Mount helper package?

amazon-efs-utils.

Try at home

  1. Mount the same EFS from a second EC2 and read hello.txt.
  2. Enable EFS Infrequent Access lifecycle (read only — then disable/delete).

In short

  1. EFS + SG 2049 + amazon-efs-utils.
  2. mount -t efs -o tls …
  3. Unmount and delete the file system after labs.

Check the mount before trusting a written file

Run findmnt against the mount point after connecting. Create one disposable file and read it from a second authorized instance in the same lab VPC. If it appears only on the first instance, confirm the mount really succeeded before troubleshooting file ownership.

Interview check What causes a timeout versus a permission denied?

A timeout suggests DNS, routing or TCP 2049 reachability to a mount target. Permission denied after connection can be filesystem ownership, access-point settings or IAM authorization depending on the mount.

Reference documentation

Practise this chapter

Interview questions and answers

Why do two hosts sometimes disagree about whether the same EFS file is visible?

One host may have written to a plain local directory after a failed mount. I would first verify both mounts and make sure they point to the intended file system. Once that is correct, I would check numeric ownership and directory permissions for the real application user.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. The /mnt/efs directory exists after the mount command failed. What should you do next?

Answer and explanation

A. Use findmnt to verify which file system is mounted there

The local directory can exist without any EFS mount. Verify the mount before using writes as evidence.

2. Which inbound port is used by the EFS NFS mount path?

Answer and explanation

B. 2049

EFS mount targets permit the NFS connection over TCP 2049 from intended client sources.

3. EFS mounted successfully, but the application user cannot write. Which layer should you check?

Answer and explanation

C. The directory’s POSIX permissions and user IDs

With the network mount established, inspect the identity and access controls used for the file operation.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

About this scenario

Singapore Freight is a logistics business in Singapore. Wei Ling Tan looks after its IT and cloud work. They count money in SGD and run their AWS resources in the ap-southeast-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 10

Easy How many addresses in a /16?

Picking a VPC size needs this count.

Singapore Freight plans the VPC 10.123.0.0/16. How many IP addresses does it hold in total?

  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Port for SSH

Security group rules need the right port.

Which TCP port must the security group open for SSH?

  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Show where you are

Before you copy or delete anything, you must know which folder you are in.

Wei Ling Tan logged in to the Singapore Freight server and is not sure which folder the terminal is in. Print the current folder path.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Read-only access to one bucket

Least privilege: give only the actions and the bucket the job needs.

Write an identity policy that lets the user read objects (s3:GetObject) only in bucket sgfreight-data.

  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Easy List all files with details

Hidden files (like .env) and file sizes or owners only show with the right options.

Show a long listing of every file, including hidden ones, in /var/www/sgfreight.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Create an EFS file system

EFS is shared storage that many servers can mount at once.

Create an encrypted EFS file system with creation token sgfreight-shared.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Storage cost

Storage is billed per GB-month.

500 GB in S3 Standard at USD 0.023 per GB-month. Monthly cost in USD?

  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Usable IPs in an AWS /24 subnet

AWS keeps 5 addresses in every subnet.

How many addresses can Singapore Freight use for servers in subnet 10.123.1.0/24 on AWS?

  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Create a mount target

Servers in a subnet reach EFS through a mount target in that AZ.

Create a mount target for fs-0abc1234 in subnet subnet-01a201dd521abb1 with security group sg-016201cc52164c3b2.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Hard S3 lifecycle rule (JSON)

Old files move to cheaper storage automatically.

Write lifecycle JSON: one Enabled rule, prefix logs/, transition to GLACIER after 90 days.

  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: NFS security group for EFS. Mount hangs forever when port 2049 is blocked between EC2 and mount targets. Allow inbound NFS (TCP 2049) on the EFS mount-target security group from the EC2 security group (not 0.0.0.0/0 in real apps). EC2 SG egress OK; EFS SG inbound 2049 source = EC2 SG id in the same VPC. sudo mount -t efs -o tls fs-xxxx:/ /mnt/efs succeeds instead of timing out.
Revision card: NFS security group for EFS · Download PNG · Open card page
Revision card: Mount helper and fstab. A manual mount is lost after reboot unless you persist it. Amazon Linux EFS mount helper uses amazon-efs-utils. fstab keeps the mount across reboots. yum/dnf install amazon-efs-utils → mkdir /mnt/efs → mount -t efs -o tls fs-id:/ /mnt/efs → add fstab line with _netdev. After reboot, df -h still shows /mnt/efs and the shared hello.txt.
Revision card: Mount helper and fstab · Download PNG · Open card page
Revision card: Unmount and delete EFS. EFS storage and mount targets keep costing if you only stop the EC2. Unmount on every instance, delete mount targets, then delete the file system. Terminate lab EC2 if you created one. umount /mnt/efs → console delete file system (mount targets first if required) → terminate EC2. EFS console list is empty for the lab FS; Cost Explorer quiet after a day.
Revision card: Unmount and delete EFS · Download PNG · Open card page
Interview card: Which port must EFS security groups allow?. NFS TCP 2049 between EC2 and EFS mount targets. Opening 2049 to the world is unsafe; source the EC2 security group id. EFS SG inbound 2049 from sg-ec2; then mount -t efs succeeds.
Interview card: Which port must EFS security groups allow? · Download PNG · Open card page
Interview card: Why add EFS to fstab?. So the mount returns after reboot without a manual remount. Use _netdev so the system waits for network before mounting NFS. fstab line with efs/_netdev and tls options via amazon-efs-utils guidance.
Interview card: Why add EFS to fstab? · Download PNG · Open card page

More cards: Ravi Sir's Cards.