How to install EFS using EFS-Helper on RHEL using the AWS user data field


This post will show you how to install EFS using EFS-Helper on RHEL using the AWS user data field. In case you don’t know, you can pass user data to an instance, that can be used to perform automated configuration tasks or run scripts after the instance starts.

You will need to modify this script and replace fs-MY_EFS_ID with your EFS storage id. The script also assumes your security groups are correctly configured allowing inbound NFS traffic. Lastly – Stunnel may be updated when you run this script. The script may not work if you download a version that is no longer available. Visit Stunnel downloads to confirm the latest version and then update the script accordingly.

You must also modify the hostname to be more suitable for your environment.

Add this script in the user data field on the ‘configure instance details’ page when you launch a new instance. The script has been developed for RHEL 7.5.

I highly recommend you use ShellCheck if you decide to make changes to the script below.

Configure Instance Details User Data
Configure Instance Details page with User Data field

The Script:

sudo hostnamectl set-hostname --static testwebserver.localdomain
cd /home/ec2-user/ || exit
sudo yum -y update
sudo yum -y install git
sudo git clone
sudo yum -y install rpm-build
cd /home/ec2-user/efs-utils/ || exit
sudo make rpm
sudo yum -y install build/amazon-efs-utils*rpm
sudo yum -y install gcc openssl-devel tcp_wrappers-devel
sudo curl -o stunnel-5.44.tar.gz
sudo tar xvfz stunnel-5.44.tar.gz
cd stunnel-5.44 || exit
sudo make install
if [[ -f /bin/stunnel ]]; then
sudo mv /bin/stunnel /root
sudo ln -s /usr/local/bin/stunnel /bin/stunnel
cd / || exit
sudo mkdir efs
sudo mount -t efs -o tls fs-MY_EFS_ID:/ efs
sudo echo $'Gofs-MY_EFS_ID /efs efs defaults,_netdev 0 0\E:x\n' | sudo vi /etc/fstab

Hopefully, this post showed you how to install EFS using EFS-Helper on RHEL using the AWS user data field. What other script do you run using the AWS user data field? Post your comment below at Anto Online.

About the Authors

Each member of Anto's editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic!

Support the Cause

Support Anto Online and buy us a coffee. Anything is possible with coffee and code.

Buy me a coffee

Leave a Reply

Your email address will not be published. Required fields are marked *