Created
January 16, 2017 16:27
-
-
Save enryold/d00ae87f85a7a23f859b099b820df9c2 to your computer and use it in GitHub Desktop.
EFS mount file system script for Elastic Beanstalk .ebconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Replace FILESYSTEM-ID-HERE and REGION-ID-HERE | |
# | |
option_settings: | |
- option_name: EFS_VOLUME_ID | |
value: FILESYSTEM-ID-HERE | |
- option_name: EFS_REGION | |
value: REGION-ID-HERE | |
- option_name: EFS_MOUNT_DIR | |
value: /efs | |
packages: | |
yum: | |
nfs-utils: [] | |
jq: [] | |
commands: | |
01_mount: | |
command: "/tmp/mount-efs.sh" | |
files: | |
"/tmp/mount-efs.sh": | |
mode: "000755" | |
content : | | |
#!/bin/bash | |
EFS_REGION=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.EFS_REGION') | |
EFS_MOUNT_DIR=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.EFS_MOUNT_DIR') | |
EFS_VOLUME_ID=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.EFS_VOLUME_ID') | |
echo "Mounting EFS filesystem ${EFS_DNS_NAME} to directory ${EFS_MOUNT_DIR} ..." | |
echo 'Stopping NFS ID Mapper...' | |
service rpcidmapd status &> /dev/null | |
if [ $? -ne 0 ] ; then | |
echo 'rpc.idmapd is already stopped!' | |
else | |
service rpcidmapd stop | |
if [ $? -ne 0 ] ; then | |
echo 'ERROR: Failed to stop NFS ID Mapper!' | |
exit 1 | |
fi | |
fi | |
echo 'Checking if EFS mount directory exists...' | |
if [ ! -d ${EFS_MOUNT_DIR} ]; then | |
echo "Creating directory ${EFS_MOUNT_DIR} ..." | |
mkdir -p ${EFS_MOUNT_DIR} | |
if [ $? -ne 0 ]; then | |
echo 'ERROR: Directory creation failed!' | |
exit 1 | |
fi | |
chmod 777 ${EFS_MOUNT_DIR} | |
if [ $? -ne 0 ]; then | |
echo 'ERROR: Permission update failed!' | |
exit 1 | |
fi | |
else | |
echo "Directory ${EFS_MOUNT_DIR} already exists!" | |
fi | |
mountpoint -q ${EFS_MOUNT_DIR} | |
if [ $? -ne 0 ]; then | |
AZ=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone) | |
echo "mount -t nfs4 -o nfsvers=4.1 ${AZ}.${EFS_VOLUME_ID}.efs.${EFS_REGION}.amazonaws.com:/ ${EFS_MOUNT_DIR}" | |
mount -t nfs4 -o nfsvers=4.1 ${AZ}.${EFS_VOLUME_ID}.efs.${EFS_REGION}.amazonaws.com:/ ${EFS_MOUNT_DIR} | |
if [ $? -ne 0 ] ; then | |
echo 'ERROR: Mount command failed!' | |
exit 1 | |
fi | |
else | |
echo "Directory ${EFS_MOUNT_DIR} is already a valid mountpoint!" | |
fi | |
echo 'EFS mount complete.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment