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.
答案 0 :(得分:1)
该问题与CodeDeploy无关。 CodeDeploy只是运行您提供的脚本;在你的情况下,node_start.bat
。也许,this question回答了你真正拥有的问题。除非您说明,否则CodeDeploy不了解您的应用程序。
您可能需要编辑node_start.bat
或您的环境,以便npm
是有效的命令。
以下是一些可以帮助您解决问题的建议:
测试您的appspec和脚本
您可以使用代理商随附的CodeDeploy local CLI来测试appspec.yml
及相关脚本。
确认您的服务正在运行
显然,如果您的部署成功,但您的应用程序实际上并未运行,那就不是很棒了。但是,您可以使用ValidateService lifecycle hook确认您的应用程序实际正在运行或进行任何其他验证。您可以包含一个脚本,该脚本可以看到进程正在运行,确认没有记录错误,运行测试或其他任何您可能需要的内容。