Elastic Beanstalk - EFS Failing to Mount on deployment - Device or resource busy
I had this same issue for a while and finally found the answer in this article from AWS Knowledge Center:
Important: You can't mount an Amazon EFS volume directly to the application directory because the contents of /var/app/current are moved to /var/app/current.old whenever you deploy an Elastic Beanstalk application.
The solution is to mount EFS to some other directory and create a symlink between that and your /current
directory, or whatever other sub directory you are mounting to in /var/app/current
.
I did this by modifying my storage-efs-mountfilesystem.config
(in .ebextensions - example efs-mountfilesystem.config) to mount to /efs
instead of /var/app/current/wwwroot/user_content
, and added a new storage-efs-symlink.config
(name it whatever you like) config file in .ebextensions that runs this command:
container_commands: 01_symlink: command: ln -s /efs ./wwwroot/user_content
Where the first argument is what you specified as your EFS mount point, and the second argument is where your app attempts to read/write to (in my case, /var/app/current/wwwroot/user_content
-> ./wwwroot/user_content
).
(Note the relative path. It needs to be relative because these commands execute when the app is still in the /var/app/staging
, so the /current
directory doesn't exist yet. More Here.)
Here was my exact error in eb-engine.log when attempting to deploy an elastic beanstalk application with EFS mounted in /var/app/current: An error occurred during execution of command [app-deploy] - [FlipApplication]. Stop running the command. Error: remove current dir failed: unlinkat /var/app/current/wwwroot/user_content: device or resource busy
If you don't already have a .ebextensions folder, you can create it yourself and make sure it ends up in your application source bundle. More information about .ebextensions here.