Noriaki Takamizawa
Noriaki Takamizawa

Reputation: 1039

ERROR: The overall deployment failed because too many individual instances failed deployment

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.

Upvotes: 16

Views: 56128

Answers (9)

Caffeine Coder
Caffeine Coder

Reputation: 1146

The error you are facing is a generic error message thrown on any of the event failure which could be beforeblockTraffic, blockTraffic, ApplicationStop etc.

enter image description here

The first step in this case would be check whether code deploy agent is running or not if first event i.e. BeforeBlockTraffic event is failed.

As you can see in the screenshot below, the event failure message would tell you the exact error behind.

enter image description here

Upvotes: 3

Nilotpal
Nilotpal

Reputation: 3588

Please check the role given to the ec2 machine(where the agent is running). It should have s3 access as well. This resolved my issue.

Upvotes: 0

Ram Acharya
Ram Acharya

Reputation: 21

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

Upvotes: 1

Frank Jose
Frank Jose

Reputation: 476

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 😃👻🕺🏾

Upvotes: 5

kishorekumaru
kishorekumaru

Reputation: 1578

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

Upvotes: 23

Srinivas Srini
Srinivas Srini

Reputation: 97

"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

Upvotes: -1

Rohit Nishad
Rohit Nishad

Reputation: 2755

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

Upvotes: 0

Purushoth
Purushoth

Reputation: 2793

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

enter image description here

Upvotes: 2

Josh McFarlane
Josh McFarlane

Reputation: 79

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.

Upvotes: 4

Related Questions