Debugging CodeDeploy Health_Constraints error

The overall deployment failed

jQN
3 min readApr 23, 2020

In one way or another, we all share the joy it is to have AWS around and it’s services. One thing we also share is the frustration of the vague documentation AWS offers when we run into an issue. I recently ran into a problem where my deploys were failing and I had zero ideas on where to start. The CodeDeploy dashboard was less than helpful and the AWS documentation was anything but cryptic, it failed to help me solve the issue or simply to tell me where to start looking for answers 😵

Let start by logging into the server and run the following command. This will give you a better idea of what’s going on as opposed to the CodeDeploy dashboard. Here is an example of the error I was seeing in the dashboard. It was rather obscure.

SSH into your server and run the following command. I’m using an Amazon Linux AMI for you it might be different based on the distro you are running.

$ tail -f /var/log/aws/codedeploy-agent/codedeploy-agent.log

The errors in the log are a bit more helpful 🤩

2020-04-23 09:45:02 INFO  [codedeploy-agent(2406)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.0-1.1597_rpm.
2020-04-23 09:45:02 ERROR [codedeploy-agent(2406)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Missing credentials - please check if this instance was started with an IAM instance profile.

It is also helpful to double-check CodeDeploy is running 🤗 now we are talking.

$ sudo service codedeploy-agent status

If it’s not running or you would like to restart it.

$ sudo service codedeploy-agent stop
$ sudo service codedeploy-agent start

Or simply run.

$ sudo service codedeploy-agent restart

In brief, this is what caused the issue in the first place. Somehow the logs brought me back in time and reminded me of what I had done wrong 🤓

I launched an instance from a snapshot and never attached the CodeDeploy IAM role to it.

To fix it go to the EC2 Dashboard select your instance and from the actions menu select Instance Settings — Attach/Replace IAM Role.

Attach a previously created role or create one if you need it.

Then restart code deploy from your server

$ sudo service codedeploy-agent restart

Finally, retry your deployment and bask on that beautiful green color of success 😎

Like always I hope this helps out and please give me some claps. Best.

--

--

jQN

I'm a Full-Stack Software Engineer who believes in the power of technology to change and improve lives. Connect with me on https://twitter.com/FullStackJQN