9

I am trying to set up auto-deployment from GitHub to AWS, using EC2. I set Role with CodeDeployServiceRole auto policy

After following the Tutorial: Use AWS CodeDeploy to Deploy an Application from GitHub, my deployment fails at the ApplicationStop event, after trying for couple of minutes with error code HEALTH_CONSTRAINT. I'm not sure how to troubleshoot the issue/where to look.

3
  • do you have old deployments before that failure? also, are you defining that step in your appspec yaml file or leaving the default ? Commented Nov 9, 2020 at 10:28
  • Also, you can find the logs of CodeDeploy agent on the server in ` /var/log/aws/codedeploy-agent` Commented Nov 9, 2020 at 10:32
  • 1
    It would be great if OP could update us on how and if they managed to resolve this issue. Commented Mar 22, 2022 at 16:50

7 Answers 7

15

These are few hints of how you can navigate your way

  • Logs as mentioned in comments in /var/log/aws/codedeploy-agent

  • As AWS support recommend you can add for one time --ignore-application-stop-failures so it will skip that step in case it failed last time and see، because the application stop Lifecycle event uses the appspec file from the last successful build so if that one is corrupted somehow this step will fail in the following builds

  • (not recommended) you can delete the file, that CodeDeploy uses to keep track of the previous successful deployment in the following path /opt/codedeploy-agent/deployment-root/deployment-instructions/

for reference on how to create a deployment using command line check the command options

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

5 Comments

Where do we set up that file
which file you mean?
Where do we setup --ignore-application-stop-failures
you can create a deployment from command line and pass this option to it check this docs.aws.amazon.com/cli/latest/reference/deploy/… @Santosh
My case was I deleted deployement_archives to gain space, and accidentally deleted the last successful build archives too, since appspec.yml doesn't change in a new build I copied appspec.yml file to the last successful build path and the error goes :)
7

Check the latest logs at /var/log/aws/codedeploy-agent

If your deployment is failing at ApplicationStop event, then most likely the issue is your EC2 instance does not have the necessary permissions to get the artifacts from S3 bucket.

  1. Your EC2 instance must have an IAM role attached which gives it enough permissions to download the artifacts from S3 bucket
  2. Your EC2 must be started with an IAM role. So you may have to reboot your instance after attaching the role to it.

From your configuration, looks like you have provided permissions to CodeDeploy to perform certain actions on your EC2. You may want to check if your EC2 also has the necessary permissions to download packages from S3 bucket.

Comments

2

Another reason for this error is that the CodeDeploy Service is not running on your machine. On Windows machines, Code Deploy Service terminates sometimes, and as a result, the deployment is not downloaded on the machine. Nothing appears in the logs either. Run services.msc and check the code deploy agent service. If it is not running, start it and retry the deployment.

Comments

0

I had the same issue and solved it by solving codedeploy-agent that wasn't working on my EC2 instance.

sudo service {httpd/apache2} status 

Something might have cause the agent not to run properly

Hope it will help

Comments

0

I had the same issue. You also need to make sure that your EC2 instance has code-deploy-agent installed.

Follow the below aws guide. It worked for me.

AWS guide to install code agent in linux server

Check if the codedeploy-agent is running.

sudo service codedeploy-agent status

if not running then use below command to run

sudo service codedeploy-agent start

Comments

0

If you are using aws Windows server, check the logs at :

C:\ProgramData\Amazon\CodeDeploy\log\codedeploy-agent-log.txt 

AWS Docs

To check if the codedeployagent running in windows. Open powersheel command window and run these command.

powershell.exe -Command Get-Service -Name codedeployagent 

Better to stop and start again.

powershell.exe -Command Stop-Service -Name codedeployagent powershell.exe -Command Start-Service -Name codedeployagent 

Or Restarting also works

powershell.exe -Command Restart-Service -Name codedeployagent

For me I had to uninstall the codedeployagent on windows by uninstalling and deleting old files of codedeploy.

Run the below command in powershell one by one to uninstall.

wmic product where name="CodeDeploy Host Agent" call uninstall /nointeractive exit 

After this delete the codedeploy folder at this location.

C:\ProgramData/Amazon/CodeDeploy/ 

Now install codedeployagent on windows.

Start the codedeployagent again.

powershell.exe -Command Start-Service -Name codedeployagent 

Comments

0

I got the same error and Its resolved only when I given permission for IAM role that I have attached with that Ec2 Server

  • AmazonEC2FullAccess
  • AmazonEC2RoleforAWSCodeDeploy
  • AmazonS3FullAccess
  • AWSCodeDeployRole

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.