Elastic Beanstalk - EFS 无法在部署时挂载 - 设备或资源繁忙

Elastic Beanstalk - EFS Failing to Mount on deployment - Device or resource busy

我正在学习 AWS 教程,该教程告诉我们如何将 EFS 系统安装到 https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-mount-efs-volumes/ 上可用的弹性 beanstalk 实例。

我将此文件夹安装在 current 文件夹中,因为我的 Web 应用程序需要将其作为路径访问,例如:public/medias。因此,我将 EFS 安装在我的应用程序 public 文件夹中,所有媒体都可以通过网络服务器访问。

第一次挂载没问题,但是第一次部署后,elastic beanstalk在清理app/current文件夹的时候好像在尝试删除文件夹,然后部署失败当前内部安装的单元带有 can not remove directory - Device or resource busy.

的消息

无法在弹性 beanstalk 的 current 文件夹内挂载 EFS 目录?或者我应该考虑将它安装在应用程序文件夹之外,然后我可以使用符号链接之类的东西通过 Web 服务器访问文件?

我将其安装在 var/app/current/public/media 中的原因是因为它需要通过 https://mywebsite.com/media/myImage.png 访问 => 这应该来自 EFS。

我可以考虑改用 S3 Buckets,但我的所有 Web 应用程序都使用静态路径读取文件,将其迁移到从存储桶中读取将是一项艰巨的工作。

我有一段时间遇到同样的问题,终于找到了答案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.

解决方案是将 EFS 挂载到其他目录并在该目录与您的 /current 目录或您挂载到 /var/app/current.[=27= 中的任何其他子目录之间创建符号链接]

我通过修改我的 storage-efs-mountfilesystem.config(在 .ebextensions - example efs-mountfilesystem.config 中)来挂载到 /efs 而不是 /var/app/current/wwwroot/user_content,并添加了一个新的 [=16] =](随便命名)运行此命令的 .ebextensions 中的配置文件:

container_commands:
  01_symlink:
    command: ln -s /efs ./wwwroot/user_content

第一个参数是您指定的 EFS 挂载点,第二个参数是您的应用程序尝试 read/write 到的位置(在我的例子中,/var/app/current/wwwroot/user_content -> ./wwwroot/user_content).

(注意相对路径,必须是相对路径,因为这些命令是在app还在/var/app/staging的时候执行的,所以/current目录还不存在。More Here.)

这是我在 eb-engine.log 中尝试部署 EFS 安装在 /var/app/current 中的弹性 beanstalk 应用程序时的确切错误: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

如果您还没有 .ebextensions 文件夹,您可以自己创建它并确保它最终出现在您的应用程序源包中。有关 .ebextensions 的更多信息 here.