I am trying to run an AfterInstall
hook in my Codedeploy deployment that runs a shell script to cd into the directory of my application give the user write privileges and then run npm install
to install application dependencies, but I receive the following error during deployment
Error CodeScriptFailed
Script Namescripts/npm-start.sh
MessageScript at specified location: scripts/npm-start.sh run as user root failed with exit code 127
Log TailLifecycleEvent - ApplicationStart
Script - scripts/npm-start.sh
[stderr]/opt/codedeploy-agent/deployment-root/dfdfdfd-c90-9f39-4ab9-bd51-e3f737003a72/d-ZID6SUV6U/deployment-archive/scripts/npm-start.sh: line 3: npm: command not found
Now I have run into issues in the past where running as sudo or root with npm
will cause issues because it is installed with my ubuntu
user, but even when I use runas: ubuntu
in my appspec.yml
it runs as user root.
Anyone have an idea what the problem could be?
appspec.yml:
version: 0.0
os: linux
files:
- source: /
destination: /var/www/app/
hooks:
AfterInstall:
- location: scripts/npm-install.sh
runas: root
timeout: 300
ApplicationStart:
- location: scripts/npm-start.sh
runas: root
timeout: 60
npm-install.sh:
#!/bin/bash
cd /var/www/app
sudo chmod g+s /var/www/app
sudo chmod o-rwx /var/www/app
npm install
npm-start.sh:
#!/bin/bash
cd /var/www/app
npm start