Extending EFS to Elastic Beanstalk

Although Elastic Beanstalk takes complete care of your environment's provisioning and configuration, there are still methods which you can used to control the advanced configuration of your environment, such as integrating your application with the likes of other AWS services, such as ElastiCache, or even EFS for that matter. This can be performed using a variety of services provided by Beanstalk itself; for example, by leveraging Beanstalk's Saved configurations, or even using Environment Manifest (YML) files. But in this particular section, we will be concentrating on integrating the EFS service with our WordPress application using specialized Configuration Files called .ebextensions.

These .ebextensions are simple YAML formatted documents ending with a .config file extension. Once the .ebextensions file is created, you need to place this in the root folder of your application's source code, within a special directory named .ebextensions, and finally, deploy your application over to Beanstalk.

These configuration files are so powerful that you don't even have to connect to your instances through SSH to issue configuration commands. You can configure your environment entirely from your project source by using .ebextensions:

  1. To start using .ebextensions for your WordPress setup, first we need to create a folder named .ebextensions within the root of your WordPress application. Type the following command from your Dev instance:
# cd wordpress && sudo mkdir .ebextensions
  1. Create a new file with an extension of .config, and paste the following contents into it:
# sudo vi efs.config

### PASTE THE FOLLOWING CONTENTS ### packages: yum: nfs-utils: [] jq: [] files: "/tmp/mount-efs.sh" : mode: "000755" content: | #!/usr/bin/env bash mkdir -p /mnt/efs EFS_NAME=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.EFS_NAME') mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $EFS_NAME:/ /mnt/efs || true mkdir -p /mnt/efs/uploads chown webapp:webapp /mnt/efs/uploads commands: 01-mount: command: "/tmp/mount-efs.sh" container_commands: 01-rm-wp-content-uploads: command: rm -rf /var/app/ondeck/wp-content/uploads 02-symlink-uploads: command: ln -snf /mnt/efs/uploads /var/app/ondeck/wp-content/uploads
You can find the complete copy of the previous code at https://github.com/yoyoclouds/Administering-AWS-Volume2.

This file causes Elastic Beanstalk to mount the newly created EFS volume on the instance's /mnt/efs directory, and also removes the wp-content/uploads, directory if it exists, and symlinks it to /mnt/efs/uploads so that it persists and is shared between instances:

  1. Once the file is created, use the eb deploy command once again to push the application directory and the newly added .ebextensions directory to your production environment.
  2. Last but not least, sign in to your production environment and select the Configuration option from the environment dashboard. Here, select the Software configuration tile and add the following key-value pair into the Environment Properties section, as shown:
  1. Here, the EFS_NAME has to have the newly created EFS filesystem's DNS name as its value. This is the same DNS name that we copied a while back once the EFS was created.

Once the deployment changes states and is made available, select the environment URL and verify whether the WordPress configurations are all working as intended or not. If you have made it this far, then you should have a really awesome, highly available, scalable, WordPress site up and running! Awesome, isn't it?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset