Hello team,
I have deployed wordpress application on Elastic Beanstalk. Now I have added one more directory named .ebextension in project root directory to mount the elastic filesystem on Beanstalk EC2 Amazon Linux instance
In this .ebextension, i have placed two files.
- i have used default storage-efs-mountfilesystem.config and updated my filesystem id and mounted directory that is /uploads
option_settings:
aws:elasticbeanstalk:application:environment:
FILE_SYSTEM_ID: 'fs-0123456789'
MOUNT_DIRECTORY: '/uploads'
##############################################
#### Do not modify values below this line ####
##############################################
packages:
yum:
amazon-efs-utils: []
commands:
01_mount:
command: "/tmp/mount-efs.sh"
files:
"/tmp/mount-efs.sh":
mode: "000755"
content : |
#!/bin/bash
EFS_MOUNT_DIR=$(/opt/elasticbeanstalk/bin/get-config environment -k MOUNT_DIRECTORY)
EFS_FILE_SYSTEM_ID=$(/opt/elasticbeanstalk/bin/get-config environment -k FILE_SYSTEM_ID)
echo "Mounting EFS filesystem ${EFS_FILE_SYSTEM_ID} 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
else
echo "Directory ${EFS_MOUNT_DIR} already exists!"
fi
mountpoint -q ${EFS_MOUNT_DIR}
if [ $? -ne 0 ]; then
echo "mount -t efs -o tls ${EFS_FILE_SYSTEM_ID}:/ ${EFS_MOUNT_DIR}"
mount -t efs -o tls ${EFS_FILE_SYSTEM_ID}:/ ${EFS_MOUNT_DIR}
if [ $? -ne 0 ] ; then
echo 'ERROR: Mount command failed!'
exit 1
fi
chmod 777 ${EFS_MOUNT_DIR}
runuser -l ec2-user -c "touch ${EFS_MOUNT_DIR}/it_works"
if [[ $? -ne 0 ]]; then
echo 'ERROR: Permission Error!'
exit 1
else
runuser -l ec2-user -c "rm -f ${EFS_MOUNT_DIR}/it_works"
fi
else
echo "Directory ${EFS_MOUNT_DIR} is already a valid mountpoint!"
fi
echo 'EFS mount complete.'
- mount.config - In this mount.config file i have updated code like below.
container_commands:
01_symlink:
command: ln -s /uploads /var/app/ondeck/wp-content/
When i deploy my code as zip into Beantsalk environment, its getting failed.
If I had a quick look at the eb-engine logs in Beanstalk,
2024/03/02 06:27:18.719789 [INFO] Error occurred during build: Command 01_symlink failed
2024/03/02 06:27:18.719827 [ERROR] An error occurred during execution of command [app-deploy] - [PostBuildEbExtension]. Stop running the command. Error: Container commands build failed. Please refer to /var/log/cfn-init.log for more details.
If I check with the cfn-init.log, I could see the below logs
2024-03-02 06:27:18,681 [ERROR] Error encountered during build of postbuild_0_MyWebsiteApplication: Command 01_symlink failed
Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/cfnbootstrap/construction.py", line 579, in run_config
CloudFormationCarpenter(config, self._auth_config, self.strict_mode).build(worklog)
File "/usr/lib/python3.9/site-packages/cfnbootstrap/construction.py", line 277, in build
changes['commands'] = CommandTool().apply(
File "/usr/lib/python3.9/site-packages/cfnbootstrap/command_tool.py", line 127, in apply
raise ToolError(u"Command %s failed" % name)
cfnbootstrap.construction_errors.ToolError: Command 01_symlink failed
2024-03-02 06:27:18,683 [ERROR] -----------------------BUILD FAILED!------------------------
2024-03-02 06:27:18,683 [ERROR] Unhandled exception during build: Command 01_symlink failed
Traceback (most recent call last):
File "/opt/aws/bin/cfn-init", line 181, in <module>
worklog.build(metadata, configSets, strict_mode)
File "/usr/lib/python3.9/site-packages/cfnbootstrap/construction.py", line 137, in build
Contractor(metadata, strict_mode).build(configSets, self)
File "/usr/lib/python3.9/site-packages/cfnbootstrap/construction.py", line 567, in build
self.run_config(config, worklog)
File "/usr/lib/python3.9/site-packages/cfnbootstrap/construction.py", line 579, in run_config
CloudFormationCarpenter(config, self._auth_config, self.strict_mode).build(worklog)
File "/usr/lib/python3.9/site-packages/cfnbootstrap/construction.py", line 277, in build
changes['commands'] = CommandTool().apply(
File "/usr/lib/python3.9/site-packages/cfnbootstrap/command_tool.py", line 127, in apply
raise ToolError(u"Command %s failed" % name)
cfnbootstrap.construction_errors.ToolError: Command 01_symlink failed
However, EFS has been mounted in /uploads directory successfully.
#mount -t nfs4
127.0.0.1:/ on /uploads type nfs4 (rw,relatime,vers=4.1,rsize=1048576,wsize=1048576,namlen=255,hard,noresvport,proto=tcp,port=20091,timeo=600,retrans=2,sec=sys,clientaddr=127.0.0.1,local_lock=none,addr=127.0.0.1)
If I check with my project directory, whether mount link has been created, But its not created.
Am I missing anything? Can any one please what should i do to resolve this?
I just updated the container_commands as you mentioned and deploy it again to Beanstalk environment. Now deployment has been succeeded, however still not performing as i desired. my mounting directory seems like looping like below ls -lh /uploads/uploads/uploads/uploads/uploads/ When i check with /var/app/ondeck/wp-content/, there also /uploads/uploads/uploads/ and sym link has been created, but looping same folder. whereas i dont see any symlink in /var/app/current/wp-content/ - Because this is my production path. /var/log/cfn-init.log logs, 2024-03-03 05:50:40,510 [INFO] -----------------------Starting build----------------------- 2024-03-03 05:50:40,515 [INFO] Running configSets: Infra-EmbeddedPreBuild 2024-03-03 05:50:40,518 [INFO] Running configSet Infra-EmbeddedPreBuild 2024-03-03 05:50:40,520 [INFO] Running config prebuild_0_MyWebsiteApplication 2024-03-03 05:50:41,472 [INFO] Command 01_mount succeeded 2024-03-03 05:50:41,473 [INFO] ConfigSets completed 2024-03-03 05:50:41,473 [INFO] -----------------------Build complete----------------------- 2024-03-03 05:50:46,362 [INFO] -----------------------Starting build----------------------- 2024-03-03 05:50:46,367 [INFO] Running configSets: Infra-EmbeddedPostBuild 2024-03-03 05:50:46,369 [INFO] Running configSet Infra-EmbeddedPostBuild 2024-03-03 05:50:46,371 [INFO] Running config postbuild_0_MyWebsiteApplication 2024-03-03 05:50:46,425 [INFO] Command 01_remove_existing_dir succeeded 2024-03-03 05:50:46,475