0

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.

2
  • What does Codedeploy say about the status of the deployment? Commented Jul 26, 2018 at 16:00
  • @Rodrigo In AWS management console code deploy says it says it is succeeded. Commented Jul 27, 2018 at 8:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.