• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

securitywing

How to Permanently Auto-Mount EFF Volume to EC2 instance using User-Data

by wing

Amazon elastic file system( EFS) can be mounted automatically using user-data while spinning up the Instance. This post aims to show both auto and manual mount of EFS volume.

Before you start mounting the EFS volume, make sure that you have the EFS ID with you and the EFS security group is open on port 2049 for the EC2 IP or subnets.

Automatic method( User data)

Add the script below into the user data section of the EC2 and then create the instance. Remember to replace the  value of file_system_id_1 and efs_mount_point_1 with the value of the EFS ID and the data directory where you want to mount the EFS volume.

#cloud-config
package_update: true
package_upgrade: true
runcmd:
- yum install -y amazon-efs-utils
- apt-get -y install amazon-efs-utils
- yum install -y nfs-utils
- apt-get -y install nfs-common
- file_system_id_1=fs-b8094b72
- efs_mount_point_1=/mnt/efs/fs1
- mkdir -p "${efs_mount_point_1}"
- test -f "/sbin/mount.efs" && printf "\n${file_system_id_1}:/ ${efs_mount_point_1} efs iam,tls,_netdev\n" >> /etc/fstab || printf "\n${file_system_id_1}.efs.eu-west-1.amazonaws.com:/ ${efs_mount_point_1} nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport,_netdev 0 0\n" >> /etc/fstab
- test -f "/sbin/mount.efs" && printf "\n[client-info]\nsource=liw\n" >> /etc/amazon/efs/efs-utils.conf
- retryCnt=15; waitTime=30; while true; do mount -a -t efs,nfs4 defaults; if [ $? = 0 ] || [ $retryCnt -lt 1 ]; then echo File system mounted successfully; break; fi; echo File system not available, retrying to mount.; ((retryCnt--)); sleep $waitTime; done;

Note: if you want to add the EFS to the ECS EC2 instance, add the below line at the end of the above script. Replace the

ECS_CLUSTER with your ECS cluster name.

– echo ECS_CLUSTER=your-cluster-name >> /etc/ecs/ecs.config

Manual Method

To mount the EFS volume manually, install the amazon-efs-utils, and use the mount command to point to a directory.

sudo yum install -y amazon-efs-utils

sudo mount -t efs -o tls efs-volume-id:/  /efs

To use IAM authentication while mounting

sudo mount -t efs -o tls,iam  efs-volume id:/  /efs

Related posts:

  1. How to Install Boto3 for AWS SDK using Anaconda in Windows
  2. How to Enable Backend Access to AWS Fargate Container Using ECS EXEC
  3. How to Upgrade AWS CDK to Minor version
  4. Top 10 Reasons Why AWS ECS is Better than Kubernetes

Filed Under: AWS

Primary Sidebar

Please help us sharing

Categories

  • AWS
  • Basics
  • Containers
  • Cryptocurrency
  • Cyber
  • Internet Security and Safety
  • IS Audit
  • IT Security Exams
  • Law & Human Rights
  • Network Security Tips
  • Off Track
  • Social Media Governance
  • Tech Comparisons
  • Tech Stack Suitability
  • Telecom
  • Tutorial

CISSP Sample Test

Take a CISSP Sample Test

CISA Sample Test

CISA IT governance Sample test

Please Follow Us

Contact us for Ads

Go to Contact Form

Search

Footer

Copyrights

Protected by Copyscape Duplicate Content Detection Software

Securitywing.com reserves the copyrights of all of its published articles.No contents of this site is permitted to be published to anywhere else in the Internet.If any contents are found in any other websites, securitywing reserves the rights to file a DMCA complaint. But you have the right to use the link of any relevant article of this site to point from your website if you consider that it might improve the quality of your article.

Tags

audit AWS backup basics browser check cisco cloud computer configuration cyber data database email gmail hsrp ids iis informaiton internet kubernetes linux load balancing malware microsoft network protection redundancy risk router security security tips server social media SSL switch test tools vpn vrrp web webserver website windows wordpress

Copyright © 2010-2025 ·All Rights Reserved · SecurityWing.com