Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Web Service CodeDeploy appspec.yml problems

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?

like image 472
Peter Bridger Avatar asked Jan 13 '15 14:01

Peter Bridger


People also ask

Where should the AppSpec Yml file be stored for AWS CodeDeploy to function properly?

If your application uses the EC2/On-Premises compute platform, the AppSpec file must be a YAML-formatted file named appspec. yml and it must be placed in the root of the directory structure of an application's source code.

What are the features of AppSpec files on an AWS Lambda compute platform?

The AppSpec file specifies the Amazon ECS task definition used for the deployment, a container name and port mapping used to route traffic, and optional Lambda functions run after deployment lifecycle events. A revision is the same as an AppSpec file. An AppSpec file can be written using JSON or YAML.

What should be checked first when an AWS CodeDeploy deployment fails?

Here's the steps I would take: Confirm that you installed the CodeDeploy agent. Confirm that you've created the IAM service role. Confirm that you have the IAM Instance Profile and that it's associated with the instance.

Which lifecycle event hook should be used in the AppSpec Yml file to ensure the application is properly running after being deployed?

AppSpec 'hooks' section for an AWS Lambda deployment An AWS Lambda hook is one Lambda function specified with a string on a new line after the name of the lifecycle event. Each hook is executed once per deployment.


1 Answers

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
like image 173
user3802205 Avatar answered Oct 21 '22 11:10

user3802205