amazon-web-servicesaws-code-deploybitbucket-aws-code-deploy

AWS CodeDeploy script exited with code 127


This is my first time using AWS CodeDeploy and I'm having problems creating my appspec.yml file.

This is the error I'm getting:

2019-02-16 19:28:06 ERROR [codedeploy-agent(3596)]:
InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: 
Error during perform: 
InstanceAgent::Plugins::CodeDeployPlugin::ScriptError - 
Script at specified location: deploy_scripts/install_project_dependencies 
run as user root failed with exit code 127 -
 /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:183:in `execute_script'

This is my appspec.yml file

version: 0.0
os: linux
files:
  - source: /
    destination: /var/www/html/admin_panel_backend
hooks:
  BeforeInstall:
    - location: deploy_scripts/install_dependencies
      timeout: 300
      runas: root
    - location: deploy_scripts/start_server
      timeout: 300
      runas: root
  AfterInstall:
    - location: deploy_scripts/install_project_dependencies
      timeout: 300
      runas: root
  ApplicationStop:
    - location: deploy_scripts/stop_server
      timeout: 300
      runas: root

And this is my project structure

drwxr-xr-x    7 501  20     224 Feb  6 20:57 api
-rw-r--r--    1 501  20     501 Feb 16 16:29 appspec.yml
-rw-r--r--    1 501  20     487 Feb 14 21:54 bitbucket-pipelines.yml
-rw-r--r--    1 501  20    3716 Feb 14 20:43 codedeploy_deploy.py
drwxr-xr-x    4 501  20     128 Feb  6 20:57 config
-rw-r--r--    1 501  20    1047 Feb  4 22:56 config.yml
drwxr-xr-x    6 501  20     192 Feb 16 16:25 deploy_scripts
drwxr-xr-x  264 501  20    8448 Feb  6 17:40 node_modules
-rw-r--r--    1 501  20  101215 Feb  6 20:57 package-lock.json
-rw-r--r--    1 501  20     580 Feb  6 20:57 package.json
-rw-r--r--    1 501  20     506 Feb  4 08:50 server.js

And deploy_scripts folder

-rwxr--r--  1 501  20  50 Feb 14 22:54 install_dependencies
-rwxr--r--  1 501  20  61 Feb 16 16:25 install_project_dependencies
-rwxr--r--  1 501  20  32 Feb 14 22:44 start_server
-rwxr--r--  1 501  20  31 Feb 14 22:44 stop_server

This is my install_project_dependencies script

#!/bin/bash
cd /var/www/html/admin_panel_backend
npm install

All the other scripts are working ok, but this one (install_project_dependencies).

Thanks you all


Solution

  • After reading a lot! I realized I was having the same problem as NPM issue deploying a nodejs instance using AWS codedeploy , I didn't have my PATH variable set.

    So leaving my start_script as this worked fine!

    #!/bin/bash
    source /root/.bash_profile
    cd /var/www/html/admin_panel_backend
    npm install
    

    Thanks!