0

​I am trying to deploy a Node.js application on windows EC2 instances. Deployment finishes successfully but node server is not started automatically on those instances. I've to login to each instance to run command node app.js to start node server. I tried to include this command in appspec.yml file but then I got below error,

LifecycleEvent - ApplicationStart
Script - node_start.bat
[stdout]
[stdout]C:\Windows\system32>cd C:/host/ 
[stdout]
[stdout]C:\host>npm start 
[stderr]'npm' is not recognized as an internal or external command,
[stderr]operable program or batch file.

My appspec.yml file is as below,

version: 0.0
os: windows
files:
  - source: app.js
    destination: c:\host
  - source: package.json
    destination: c:\host
  - source: \node_modules
    destination: c:\host\node_modules
  - source: node_start.bat
    destination: c:\host
  - source: before_install.bat
    destination: c:\host
hooks:
    AfterInstall:
    - location: before_install.bat
      timeout: 300
    ApplicationStart:
    - location: node_start.bat
      timeout: 300

Node is already installed on those two instances and Path variable is also properly set. Logging manually to those servers and running command npm start works perfectly fine. It fails only though AWS Code deploy. I want to introduce AWS Lambda function also after this step to do health check.

Any help to resolve this issue would be greatly appreciated.

Anky
  • 111
  • 15

1 Answers1

1

The issue isn't really related to CodeDeploy. CodeDeploy simply runs the script that you give it; in your case, node_start.bat. Perhaps, this question answers the issue that you're really having. CodeDeploy has no knowledge of your application unless you tell it.

You will likely either need to edit node_start.bat or your environment so that npm is a valid command.

Here are a couple of suggestions to help your case:

Test your appspec and scripts

You can test your appspec.yml and related scripts using the CodeDeploy local CLI, which comes with the agent.

Validate that your service is running

Obviously, it's not awesome if your deployment succeeds, but your application is not actually running. However, you can use the ValidateService lifecycle hook to confirm that your application is actually running or any other validation. You can include a script that can see that the process is running, confirm that no errors are getting logged, run tests, or whatever else you might want.

EmptyArsenal
  • 7,314
  • 4
  • 33
  • 56