5
votes

I'm trying to deploy using CircleCI -> S3 -> CodeDeploy -> EC2. I was able to upload deploy image onto S3 from CircleCI, but unable to deploy S3 to EC2 instance. Here's the error.

The overall deployment failed because too many individual instances failed deployment, too few healthy instances are available for deployment, or some instances in your deployment group are experiencing problems. (Error code: HEALTH_CONSTRAINTS)

The error was provided from CodeDeploy. I can't figure out why and how. I'd appreciate if you give some advise.

7

7 Answers

7
votes

If you are running on Ubuntu there might be plenty of reasons, here is a checklist can verify

Check code-deploy agent is installed on your EC2 Instance. Please refer this document to install code deploy agent. https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-ubuntu.html

$ sudo service codedeploy-agent status

In case if you are running Ubuntu release 20.x and you get this error

./install:22:in block in method_missing': undefined method path' for #<IO:> (NoMethodError)

try running the install file via this script

sudo ./install auto > /tmp/logfile
  1. Check you have EC2 Instance Code Deploy Role -> Create a code deployment role and assign it to the Instance, https://docs.aws.amazon.com/codedeploy/latest/userguide/getting-started-create-service-role.html.

In case if you assign the EC2 Role after initiate, restart the server.

  1. Check your appsec.yml file placement as per the top answer, try to avoid any long timeout in it.

  2. Log into your instance check your error log

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

4
votes

You should be able to figure out what caused the individual instances to fail by digging into the deployment instance details: http://docs.aws.amazon.com/codedeploy/latest/userguide/how-to-view-instance-details.html

These should contain more detailed information about why your application was unable to be deployed.

1
votes

Make sure the CodeDeploy Host Agent Service is running in your target EC2 instance.

enter image description here

0
votes

From the failed deployments, I can see all lifecycle events were skipped. Instance i-0bcc36e73851297f2 is currently in Stopped state but I can see the IAM instance profile is missing. Your Amazon EC2 instances need permission to access the Amazon S3 buckets or GitHub repositories where the applications that will be deployed by AWS CodeDeploy are stored. To launch Amazon EC2 instances that are compatible with AWS CodeDeploy, you must create an additional IAM role, an instance profile. 1

For such failures, you can always begin with a general troubleshooting checklist for a failed deployment 2 and then look for troubleshooting guides on Deployment Issues and Instance issues3.

1[http://docs.aws.amazon.com/codedeploy/latest/userguide/how-to-create-iam-instance-profile.html]1

2 [http://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting-general.html]2

3 [http://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting.html]3

0
votes

This error is commonly due to problems in the configuration of the appSpec.yml or appSpec.json file (It depends on the format you are using).

"If you have any Hook I recommend that you remove them, check if it works, then you can add one by one (the Hooks) and so you can identify the error"

The appspec.yml file should be located at the root of your project:

   │-- appspec.yml
   │-- index.html
   └-- scripts
       │-- install_dependencies
       │-- start_server
       └-- stop_server

In the scripts folder you will have to place the processes that you want to be executed according to the Hook

Here is an example of the appspec.yml file

version: 0.0
os: linux
files:
  - source: /index.html
    destination: /var/www/html/
hooks:
  BeforeInstall:
    - location: scripts/install_dependencies
      timeout: 300
      runas: root
    - location: scripts/start_server
      timeout: 300
      runas: root
  ApplicationStop:
    - location: scripts/stop_server
      timeout: 300
      runas: root

I hope I can help you 😃👻🕺🏾

-1
votes

"The CodeDeploy agent did not find an AppSpec file within the unpacked revision directory at revision-relative path 'appspec.yml'"

Please place your appspec.yml file in your root folder to solve this error

To access your after script and before script

-1
votes

Check the status of the Code Deploy Agent. In my case, the agent wasn't up.