AWS EC2 user data - how do I debug failed EFS mount failure

0 votes

I'm using an EFS volume on my EC2 instance (Using Amazon linux AMI). I am able to mount the volume easily. If I try to shell into the server and run something like:

sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-xxxxxxxxx.efs.us-southwest-2.amazonaws.com:/efs

But when I add a shell script inside the user data section of my instance and then boot it, nothing displays there, how do I find this bug/problem? Are there some logs or something in the filesystem I can take reference from? I don't get to see any errors, just no mounted drive. Any help is appreciated.

I'm using the following shell script:

#!/bin/bash
# Make sure all packages are up-to-date
yum update -y

# Make sure that NFS utilities and AWS CLI utilities are available
yum install -y jq nfs-utils python27 python27-pip awscli
pip install --upgrade awscli

# Name of the EFS filesystem (match what was created in EFS)
EFS_FILE_SYSTEM_NAME="xxxx.efs.ap-southeast-2.amazonaws.com"

# Gets the EC2 availability zone for the current ECS instance

EC2_AVAIL_ZONE="us-west-1a"
# Gets the EC2 region for the current ECS instance

EC2_REGION="US West(N.Claifornia)"

# Creates the mount-point for the EFS filesystem
DIR_TGT="efs"
mkdir "${DIR_TGT}"

# Get the EFS filesystem ID.
EFS_FILE_SYSTEM_ID="$(/usr/local/bin/aws efs describe-file-systems --region "${EC2_REGION}" | jq '.FileSystems[]' | jq "select(.Name==\"${EFS_FILE_SYSTEM_NAME}\")" | jq -r '.FileSystemId')"

if [ -z "${EFS_FILE_SYSTEM_ID}" ]; then
    echo "ERROR: variable not set" 1> /etc/efssetup.log
    exit
fi

# Create the mount source path
DIR_SRC="${EC2_AVAIL_ZONE}.${EFS_FILE_SYSTEM_ID}.efs.${EC2_REGION}.amazonaws.com"

# Actually mount the EFS filesystem
mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,soft,timeo=600,retrans=2 "${DIR_SR
Jul 4, 2018 in AWS by Hammer
• 360 points

edited Jul 4, 2018 by Hammer 2,702 views

1 answer to this question.

0 votes

You can find the UserData logs at cloud-init-output.log

/var/log/cloud-init.log and
/var/log/cloud-init-output.log

Your EC2_REGION should be ap-soutwest-2 not US West (California), Since you have mentioned the Endpoint name already, you don't need to construct the EFS endpoint.

mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,soft,timeo=600,retrans=2 "${EFS_FILE_SYSTEM_NAME}:/" "${DIR_TGT}"

If you wish to construct the endpoint, then take reference from this website: Here

file-system-id.efs.aws-region.amazonaws.com

So, it should be

DIR_SRC="${EFS_FILE_SYSTEM_ID}.efs.${EC2_REGION}.amazonaws.com"
answered Jul 4, 2018 by Cloud gunner
• 4,670 points

Related Questions In AWS

0 votes
0 answers
0 votes
1 answer
+1 vote
2 answers

How do I get my AWS Glue client in JAVA?

Hey, you've been using a correct code ...READ MORE

answered Apr 17, 2018 in AWS by Cloud gunner
• 4,670 points
4,825 views
0 votes
1 answer
0 votes
1 answer
+2 votes
3 answers
+1 vote
2 answers

How do I run python script on aws EC2 instance(ubuntu)?

I believe that you are using the ...READ MORE

answered Apr 17, 2018 in AWS by Cloud gunner
• 4,670 points
10,204 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP