Deploy NodeJS server to AWS CodeDeploy ApplicationStart timeout

74 views Asked by At

Im deploying a Nodejs server using a appspec.yml file with the following content

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/SimpleNodeJSServer
    overwrite: true
file_exists_behavior: OVERWRITE
hooks:
  AfterInstall:
    - location: deployment-scripts/install_dependencies.sh
      timeout: 1000
      runas: root
  ApplicationStart:
    - location: deployment-scripts/start_server.sh
      timeout: 300
      runas: root

The AfterInstall runs well and also the ApplicationStart. The problem is the command in ApplicationStart never exits the script and get eventually a timeout.

cd /home/ubuntu/SimpleNodeJSServer
npm run ci-build
npm run start
exit 0

I have tried both with and without the exit 0 but both get timeout. It makes sense as the npm start (node ./dist/src/index.js which run app.listen()) is blocked by the running server as I understand. But how can I make the script be over? I think im missing something basic here. Thank you for the help

1

There are 1 answers

3
Allan Chua On

You can use nohup to run the app on the background:

nohup npm run start &

Alternatively, you can try to use this to silence the logs

nohup npm start 2>/dev/null 1>/dev/null&

You can also change the definition of the start script inside the package.json file.

nohup node ./dist/src/index.js &