Amazon Web Service CodeDeploy appspec.yml problems

Peter Bridger picture Peter Bridger · Jan 13, 2015 · Viewed 10.4k times · Source

I have a Node.js application which is being automatically deployed to Amazon Web Service through Codeship using the CodeDeploy AWS deployment system.

During the deployment process I've set in my appspec.yml for the currently running web application to be stopped. Once the deployment is complete, I want the web application to be started up again.

os: linux
files:
  - source: /
    destination: /var/www/app2
hooks:
  AfterInstall:
      - location: bash_scripts/stop_forever.sh
        runas: ec2-user
  ApplicationStart:
      - location: bash_scripts/start_forever.sh
        runas: ec2-user

However I've not yet been able to have either of these scripts to be called successfully from the appspec.yml file during a deployment.

The current error I'm seeing in the AWS deployment agent log is

Error CodeScriptMissing
Script Name /var/scripts/stop_forever.sh
MessageScript does not exist at specified location: /var/scripts/stop_forever.sh
Log TailLifecycleEvent - ApplicationStop

This seems to refer to an older version of the appspec.yml file which was attempting to run these scripts in a different location. Even though I've changed the contents of the appspec.yml file in the deployed package, this error message remains the same on each deploy.

In addition to appspec.yml file listed above, I've also tried making the following changes:

  • Not listing a runas parameter for each hook
  • Referencing a script inside the deployed directory
  • Referencing a script outside the deployed directory
  • Having a version parameter initially set to 0.0

Unfortunately there is very little online in terms of appspec.yml troubleshooting, other than the AWS documentation.

What very obvious thing I am doing wrong?

Answer

user3802205 picture user3802205 · Jan 13, 2015

The ApplicationStop hook is being called from the previously installed deployment before trying to run the current deployment appspec.yml file.

In order to prevent this from happening you'll have to remove any previously installed deployment from the server.

  • Stop the code deploy agent - sudo service codedeploy-agent stop
  • clear all deployments under /opt/codedeploy-agent/deployment-root
  • Restart the code deploy agent - sudo service codedeploy-agent start