我正在使用 AWS CodeDeploy 将代码部署到我们的 AWS Amazon Linux 实例。我关注了这篇知识库文章 https://aws.amazon.com/premiumsupport/knowledge-center/codedeploy-agent-non-root-profile/让代理在 ec2-user 上下文而不是 root 中执行
在进行更改之前,yml 文件中的脚本按预期执行(但我们需要脚本在非 root 上下文中执行)并且设置 runas: 部分 appspec.yml 文件似乎没有执行脚本预期的 ec2-user 上下文
应用规范.yml:
version: 0.0
os: linux
files:
- source: /
destination: /home/ec2-user/veddor/api
owner: ec2-user
hooks:
AfterInstall:
- location: deploy/script/deploy-veddor-api.sh
timeout: 300
runas: ec2-user
自从进行更改后,现在显示此错误而不是执行 appspec 文件中指定的脚本
LifecycleEvent - AfterInstall
Script - deploy/script/deploy-veddor-api.sh
[stderr]Password: su: Authentication failure
deploy-veddor-api.sh 的内容
cp /home/ec2-user/veddor/api/deploy/config/Config-roddev.php /home/ec2-user/veddor/api/app/config/Config.php
cd /home/ec2-user/veddor/api
chmod +x ./composer.phar
php ./composer.phar install
我正在寻求帮助,以弄清楚我需要做什么才能使脚本 deploy-veddor-api.sh 在 ec2-user 上下文中实际运行。
最佳答案
您可能正在以非根用户身份运行 AWS CodeDeploy 代理。只有 root 能够在您的 AfterInstall
Hook 中拥有一个 runas
用户,因为没有密码身份验证,没有其他用户帐户可以运行替代用户“su”命令。
在 AWS 的 appspec 用户指南中查看“runas”的详细信息:
https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html
runas Optional. The user to impersonate when running the script. By default, this is the AWS CodeDeploy agent running on the instance. AWS CodeDeploy does not store passwords, so the user cannot be impersonated if the runas user needs a password. This element applies to Amazon Linux and Ubuntu Server instances only.
如果您已经以 ec2-user
身份运行 CodeDeploy Agent,则无需在 AfterInstall
中提供 runas
元素钩子(Hook)。
关于linux - 在非根上下文中运行 linux AWS CodeDeploy 代理时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48159084/