AWS CodeDeploy Command Not Found

拜拜、爱过 提交于 2021-02-07 14:35:41

问题


When trying to deploy a Node.js application I'm getting an error npm: command not found in my post_install.sh AfterInstall script. What's super strange is in my BeforeInstall script I run npm install -g pm2 and it works perfectly fine without any errors.

Both are being run as the ubuntu user. Why would this command work in one CodeDeploy script and fail in another?


回答1:


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.




回答2:


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.

This is what happened when I executed my script manually 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:

# 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)


来源:https://stackoverflow.com/questions/46048453/aws-codedeploy-command-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!