简体   繁体   English

找不到 AWS CodeDeploy 命令

[英]AWS CodeDeploy Command Not Found

When trying to deploy a Node.js application I'm getting an error npm: command not found in my post_install.sh AfterInstall script.尝试部署 Node.js 应用程序时出现错误 npm:在我的post_install.sh AfterInstall 脚本中npm: command not found What's super strange is in my BeforeInstall script I run npm install -g pm2 and it works perfectly fine without any errors.超级奇怪的是,在我的 BeforeInstall 脚本中,我运行npm install -g pm2 ,它运行良好,没有任何错误。

Both are being run as the ubuntu user.两者都以ubuntu用户身份运行。 Why would this command work in one CodeDeploy script and fail in another?为什么此命令在一个 CodeDeploy 脚本中有效而在另一个脚本中失败?

Looks like I was able to solve this by adding the following to my script files. 看起来我能够通过在脚本文件中添加以下内容来解决这个问题。

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Hopefully this can help someone. 希望这可以帮助某人。

I got the same problem trying to invoke the aws cli in my shell script during the AfterInstall hook, in an ubuntu server with ubuntu user. 我在使用ubuntu用户的ubuntu服务器中尝试在AfterInstall挂钩期间调用我的shell脚本中的aws cli时遇到了同样的问题。

This is what happened when I executed my script manually sh ecr-login.sh : 这是我手动执行脚本时发生的事情sh ecr-login.sh

# Works
$(aws ecr get-login --no-include-email --region sa-east-1)

# Works
$(/home/ubuntu/.local/bin/aws ecr get-login --no-include-email --region sa-east-1)

When CodeDeploy executed it: 当CodeDeploy执行它时:

# Not Work
$(aws ecr get-login --no-include-email --region sa-east-1)

# Works
$(/home/ubuntu/.local/bin/aws ecr get-login --no-include-email --region sa-east-1)

I got the same problem trying to invoke the aws cli in my shell script during the After Install hook, in an ubuntu20 server with ubuntu user.我在安装后挂钩期间尝试在我的 shell 脚本中调用 aws cli 时遇到了同样的问题,在具有 ubuntu 用户的 ubuntu20 服务器中。

I have checked inside /usr/bin/ folder on server yarn/pm2/node are running are not If not run below command root@ip-:/# ln -s /root/.nvm/versions/node/v16.17.0/bin/node /usr/bin/ root@ip-:/# ln -s /root/.nvm/versions/node/v16.17.0/bin/pm2 /usr/bin/ root@ip-:/# ln -s /root/.nvm/versions/node/v16.17.0/bin/yarn /usr/bin/我已经检查了服务器 yarn/pm2/node 上的 /usr/bin/ 文件夹是否正在运行 如果没有在命令 root@ip-:/# ln -s /root/.nvm/versions/node/v16.17.0/ 下运行bin/node /usr/bin/ root@ip-:/# ln -s /root/.nvm/versions/node/v16.17.0/bin/pm2 /usr/bin/ root@ip-:/# ln -s /root/.nvm/versions/node/v16.17.0/bin/yarn /usr/bin/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM