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 305 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,240 points

Related Questions In AWS

+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,240 points
637 views
0 votes
2 answers

How do I define the principal for an AWS policy statement?

Check with AWS Policy Documentations once, rest ...READ MORE

answered Jun 25, 2018 in AWS by Cloud gunner
• 4,240 points

edited Jun 26, 2018 by Cloud gunner 54 views
0 votes
1 answer

AWS EC2 Free Tier- how many instances can i run?

Amazon has a handy page that details ...READ MORE

answered Jul 6, 2018 in AWS by Priyaj
• 56,120 points
156 views
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,240 points
1,371 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.