How to install AWS EFS on RHEL (Updated 2021)

This guide will show you how to install AWS EFS using EFS-Helper on RHEL. Additionally, you will see how to use the AWS EC2 user data field to auto-configure your RHEL instance.

YouTube player

Let’s get started!

You will need to modify the script below and replace fs-MY_EFS_ID with your EFS storage id. The script also assumes your security groups are correctly configured, allowing inbound traffic.

Lastly, Stunnel may be updated when you run this script. Therefore, 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.

It would be best if you also modify the hostname to be more suitable for your environment.

The AWS EFS install script for RHEL

The script below will install AWS EFS on your RHEL instance:

#!/bin/bash
sudo hostnamectl set-hostname --static testwebserver.localdomain
cd /home/ec2-user/ || exit
sudo yum -y update
sudo yum -y install git
sudo git clone https://github.com/aws/efs-utils
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 https://www.stunnel.org/downloads/stunnel-5.44.tar.gz
sudo tar xvfz stunnel-5.44.tar.gz
cd stunnel-5.44 || exit
./configure
make
sudo make install
if [[ -f /bin/stunnel ]]; then
sudo mv /bin/stunnel /root
fi
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

Run the script via AWS EC2 user data

You can also run the script via AWS EC2 user data if you wish the instance to be auto-configured with your EFS mount. To do this, add this script in the user data field on the ‘configure instance details’ page when launching a new instance.

Example of the user data field under advanced details when configuring an AWS EC2 instance:

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

Frequently asked questions

What is Stunnel?

Stunnel (“Secure Tunnel”) is a cross-platform proxy application designed for clients and servers. Additionally, Stunnel uses the OpenSSL library for cryptography.

What is AWS EFS?

AWS Amazon Elastic File System (EFS) automatically grows and shrinks as you add and remove files. With AWS EFS, there is no need for management or provisioning.

What is AWS EFS Helper?

The AWS EFS (mount) helper helps you mount your EFS file systems. It includes the AWS EFS recommended options by default. Additionally, the mount helper has built-in logging for troubleshooting purposes.

What is AWS User Data?

You have the option of passing user data to an AWS EC2 instance when launching it. In addition, the user data field can perform common automated configuration tasks and even run scripts after the instance starts.

You may also be interested in

About Anto Online

Anto, a seasoned technologist with over two decades of experience, has traversed the tech landscape from Desktop Support Engineer to enterprise application consultant, specializing in AWS serverless technologies. He guides clients in leveraging serverless solutions while passionately exploring cutting-edge cloud concepts beyond his daily work. Anto's dedication to continuous learning, experimentation, and collaboration makes him a true inspiration, igniting others' interest in the transformative power of cloud computing.

View all posts by Anto Online

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.