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

who*_*ate 12 hook chmod amazon-elastic-beanstalk ebextensions

语境

我正在使用 Elastic Beanstalk 部署一个非常简单的测试应用程序。我有几个要使用 apt 安装的软件包。我01_installations.sh.platform/hooks/prebuild目录中包含了一个安装脚本。当我压缩我的应用程序并部署到 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  
Run Code Online (Sandbox Code Playgroud)

我的理解是权限被拒绝,因为我没有添加chmod +x以使 .sh 文件可执行。正如 AWS 平台挂钩文档所述:“使用 chmod +x 设置挂钩文件的执行权限。” (https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html)。我的问题是:我该怎么做?

我只是在一个目录中有 .sh 文件。我不会从其他任何地方调用它。我错过了一个简单的步骤吗?AWS 文档使它看起来应该很简单。

以前的尝试

我尝试过的事情:

  1. 添加 .ebextensions
    • 尝试:使用以下命令.config.ebextensions目录中创建一个文件,该文件应该使用 chmod +x 权限执行 .sh 文件。
    • 结果:出现同样的错误。Elastic Beanstalk 日志根本不表明.config已处理。
container_commands:
    01_chmod1:
        command: "chmod +x .platform/hooks/prebuild/01_installations.sh"
Run Code Online (Sandbox Code Playgroud)
  1. 更改 .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 
Run Code Online (Sandbox Code Playgroud)

我已经回顾了这里的想法,但实际上没有一个包含足够完整的示例来遵循:

Kha*_*ear 7

确保您的文件在 git 中可执行

chmod +x path/to/file
git update-index --chmod=+x path/to/file
Run Code Online (Sandbox Code Playgroud)

参考 如何在 GIT 中为文件添加 chmod 权限?

  • 同样在窗户上也能发挥作用 (2认同)
  • 对于我在 Windows 10 上使用 Git Bash 不起作用。不知道它对其他人如何起作用。也许他们正在使用 WSL 而不是 Git Bash。 (2认同)

Mar*_*cin 6

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

但是,如果您想在 EB 实例上执行此操作,则不能container_commands用于此目的。其原因是,container_commands执行之后 prebuild。相反,您应该尝试使用commands

预构建文件在运行任何配置文件的命令部分中的命令之后和运行 Buildfile 命令之前运行。