0
votes

I have just started working with AWS. I am trying to deploy a nodejs application using codeship and AWS codedeploy. I am successful in deploying the application from codeship to Ec2 instance. But the problem is that I am not able to run the hooks file in appspec.yml. My appspec.yml is given below:

--- 
version: 0.0
os: linux
files: 
  - destination: /home/ec2-user/node-project
    source: /
hooks:  
ApplicationStart: 
  - location: bin/app-start.sh
    runas: root
    timeout: 100   

In app-start.sh I have:

#!/bin/bash
npm install

The app-start.sh never works and node-modules are never installed. I have also tried to debug in the logs path(/var/log/aws/codedeploy-agent/codedeploy-agent.log) for code-deploy but there is no error and warning.I have also tried multiple things but nothing is working.

The project is successfully installed in Ec2 instance but appspec.yml never launches app-start.sh. Any help would be appreciated.

1
What does Codedeploy say about the status of the deployment?Rodrigo M
@Rodrigo In AWS management console code deploy says it says it is succeeded.Developer

1 Answers

1
votes

The issue is that you're moving the files to /home/ec2-user/node-project, which happens before your app-start.sh gets run at the ApplicationStart lifecycle hook. You need to cd into the right directory before running npm install.

Updated ApplicationStart scripts:

#!/bin/bash
cd /home/ec2-user/node-project
npm install
# You'll need to start your application too.
npm start

As an aside, you may want to use the AfterInstall lifecycle hook to run npm install just for organization purposes, but it will have no functional different.