背景
我正在使用 Elastic Beanstalk 部署一个非常简单的测试应用程序。我有几个要使用 apt 安装的软件包。我在 .platform/hooks/prebuild
目录中包含了一个名为 01_installations.sh
的脚本文件来进行安装。当我将应用程序压缩并部署到 Elastic Beanstalk 时,日志确认 prebuild 脚本已运行,但是它没有权限。
2020/08/12 21:03:46.674234 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2020/08/12 21:03:46.674256 [INFO] Executing platform hooks in .platform/hooks/prebuild/
2020/08/12 21:03:46.674296 [INFO] Following platform hooks will be executed in order: [01_installations.sh]
2020/08/12 21:03:46.674302 [INFO] Running platform hook: .platform/hooks/prebuild/01_installations.sh
2020/08/12 21:03:46.674482 [ERROR] An error occurred during execution of command [app-deploy] - [RunAppDeployPreBuildHooks]. Stop running the command. Error: Command .platform/hooks/prebuild/01_installations.sh failed with error fork/exec .platform/hooks/prebuild/01_installations.sh: permission denied
问题
我的理解是权限被拒绝是因为我没有添加 chmod +x
使 .sh 文件可执行。正如 AWS 平台钩子文档所述:“使用 chmod +x 在您的钩子文件上设置执行权限” (https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html)。 我的问题是:我该如何做这个?
我只是在一个目录中有这个 .sh 文件。我没有从任何其他地方调用它。我是否缺少简单的步骤?AWS 文档让它看起来应该很简单。
之前尝试过的方法
我尝试过以下方法:
- 添加 .ebextensions
- 尝试:在 .ebextensions 目录下创建一个 .config 文件,并使用下面的命令以 chmod +x 权限执行 .sh 文件。
- 结果:出现相同的错误。Elastic Beanstalk 日志并未指示已处理 .config 文件。
container_commands:
01_chmod1:
command: "chmod +x .platform/hooks/prebuild/01_installations.sh"
- 更改.sh文件的名称
- 尝试:根据AWS用户(链接如下)的建议,将.sh文件更名为“chmod + x 01_installations.sh”。删除.ebextensions
- 结果:仍然出现相同的错误。
[RunAppDeployPreBuildHooks]. Stop running the command. Error: Command .platform/hooks/prebuild/chmod +x 01_installations.sh failed with error fork/exec .platform/hooks/prebuild/chmod +x 01_installations.sh: permission denied
我已经审核了这里的想法,但它们中没有一个包含足够完整的示例可供参考: