0
votes

I am following the AWS tutorial that tells us how to mount EFS system to elastic beanstalk instances available at https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-mount-efs-volumes/.

I am mounting this folder inside the current folder, as it needs to be accessible by my web application as a path, e.g: public/medias. So I am mounting EFS inside my app public folder and all media will be accessible through the webserver.

The first mount is ok, but after the first deployment, it seems that elastic beanstalk is trying to remove the folder when clearing up the app/current folder for a new deployment, then the deploy fails to remove the mounted unit which is inside current with a message that can not remove directory - Device or resource busy.

It's not possible to mount EFS directories inside current folder for elastic beanstalk? Or I should consider in mounting it outside of the application folder then I could use something like symlink for accessing the files through a web server?

The reason why I am mounting this inside var/app/current/public/media is because it needs to be accessible through https://mywebsite.com/media/myImage.png => this should come from EFS.

I could consider using S3 Buckets instead but all my web application is reading files using a static path and it would be a massive work to migrate that to read from a bucket.

1

1 Answers

1
votes

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.