如何向 AWS Elastic Beanstalk 平台挂钩添加 chmod +x 权限?

How do you add chmod +x permission to an AWS Elastic Beanstalk platform hook?

上下文

我正在使用 Elastic Beanstalk 部署一个非常简单的测试应用程序。我有几个要使用 apt 安装的软件包。我在 .platform/hooks/prebuild 目录中的安装中包含了一个 01_installations.sh 脚本。当我压缩我的应用程序并部署到 Elastic Beanstalk 时,日志确认预构建脚本运行,但它没有权限。

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 文档让它看起来应该很简单。

之前的尝试

我尝试过的事情:

  1. 添加 .ebextensions
    • 尝试:使用以下命令在 .ebextensions 目录中创建一个 .config 文件,该命令应以 chmod +x 权限执行 .sh 文件。
    • 结果:出现同样的错误。 Elastic Beanstalk 日志根本不表示 .config 已被处理。
container_commands:
    01_chmod1:
        command: "chmod +x .platform/hooks/prebuild/01_installations.sh"
  1. 正在更改 .sh 文件的名称
    • 尝试:按照 AWS 用户(下面的论坛 link)的建议,将 .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 

我已经回顾了此处的想法,但其中 none 实际上包含了足够完整的示例以供遵循:

通常在压缩部署包之前,您会在 本地工作站 上设置权限。

但是,如果您想在 EB 实例上执行此操作,则不能使用 container_commands。原因是container_commands执行afterprebuild。相反,您应该尝试使用 commands:

The prebuild files run after running commands found in the commands section of any configuration file and before running Buildfile commands.

确保在 git

中使您的文件可执行
chmod +x path/to/file
git update-index --chmod=+x path/to/file

参考自 How to add chmod permissions to file in GIT?

在更新权限提交更改后,这对我有用。

.config 文件中的命令也将不起作用,因为这些命令将 运行 预部署,因此将无法找到 .sh 文件的路径。