1

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
cphill
  • 5,596
  • 16
  • 89
  • 182

1 Answers1

0

How do you know that npm is properly installed and set up on your box? In this question and this question, you can see users having a similar issues. It sounds like you'll need to re-install NodeJS to get NPM happy again.

You should log onto your box, and try running sudo npm install yourself. If it works in that scenario, you should check your .bash* files to see if you do anything to put npm in your path or something that might impact how it runs. If you can confirm that your setup is ok in non-CodeDeploy scenarios, you could debug the CodeDeploy scenario specifically, but I'm guessing it's your setup.

EmptyArsenal
  • 7,314
  • 4
  • 33
  • 56