...

/

Modifying EC2 User Data to Mount EFS

Modifying EC2 User Data to Mount EFS

Learn to update the launch template to mount the EFS file system.

Now that we’ve copied wp-content files to EFS, we just need to make sure that all our WordPress instances use it automatically.

The following script will do exactly that. Lets go through it:

Press + to interact
# 1. Stop all Wordpress services
gonit stop all
# 2. Install NFS
apt-get update
apt-get -y install nfs-common
# 3. Create the folder for EFS
mkdir /efs
# 4. Add the EFS volume to the mount targets
echo "<file-system-id>.efs.us-east-2.amazonaws.com:/ /efs efs nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport 0 0" >> /etc/fstab
# 5. Mount all file systems
mount -a
# 6. Change the wp-content link to the EFS file system
rm /opt/bitnami/wordpress/wp-content
ln -s /efs/wp-content /opt/bitnami/wordpress/wp-content
# 7. Restart all WordPress services
gonit start all

We can add the instructions to the EC2 user data script so they will run on the first boot of our WordPress instances.

Let’s go through the steps one by one:

  • Line 2: We use gonit stop all to stop all WordPress serivies.
  • Lines 5–6: We install the NFS components.
  • Line 9: We create the /efs folder.
  • Line 12: We set up the mount command for the EFS file system. This command is different from what we did in the last lesson. Here, we add the mount command to the /etc/fstab file, which maintains mount targets permanently. The options are exactly the same as in
...