5

i've set up everything according to this article

https://aws.amazon.com/tw/blogs/apn/announcing-atlassian-bitbucket-support-for-aws-codedeploy/

Here is my env:

Instance (free tier with amazon linux)
- apache 2.4 installed

Security group
- only 22 (only my ip can access) and 80 port are opened

Iptables stopped

2 roles are set
- one for linking S3 <-> bitbucket (attached custom policy)
- one role is for deployment group (attached AWSCodeDeployRole policy)

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": "codedeploy.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

The script tried to deploy is
https://s3.amazonaws.com/aws-codedeploy-us-east-1/samples/latest/SampleApp_Linux.zip

Permission /var/www/* is owned by ec2-user with 755 permission

Agent service codedeploy-agent status = The AWS CodeDeploy agent is running as PID 7200

Clues: There are some zip file in my s3 bucket is uploaded for every deploy.

Error code: HEALTH_CONSTRAINTS

Anyone have an idea what the causes of deployment fail?

update1 After i re-launch the instance with iam profile, the application can be deployed. But it is still failed, when i click view events, there is log as follow:

Error CodeScriptFailed
Script Namescripts/install_dependencies
MessageScript at specified location: scripts/install_dependencies run as user root failed with exit code 1
Log TailLifecycleEvent - BeforeInstall
Script - scripts/install_dependencies
[stdout]Loaded plugins: priorities, update-motd, upgrade-helper
[stdout]Resolving Dependencies
[stdout]--> Running transaction check
[stdout]---> Package httpd.x86_64 0:2.2.31-1.8.amzn1 will be installed
[stdout]--> Processing Dependency: httpd-tools = 2.2.31-1.8.amzn1 for package: httpd-2.2.31-1.8.amzn1.x86_64
[stdout]--> Processing Dependency: apr-util-ldap for package: httpd-2.2.31-1.8.amzn1.x86_64
[stdout]--> Running transaction check
[stdout]---> Package apr-util-ldap.x86_64 0:1.4.1-4.17.amzn1 will be installed
[stdout]---> Package httpd-tools.x86_64 0:2.2.31-1.8.amzn1 will be installed
[stdout]--> Processing Conflict: httpd24-2.4.23-1.66.amzn1.x86_64 conflicts httpd < 2.4.23
[stdout]--> Processing Conflict: httpd24-tools-2.4.23-1.66.amzn1.x86_64 conflicts httpd-tools < 2.4.23
[stdout]--> Finished Dependency Resolution
[stderr]Error: httpd24-tools conflicts with httpd-tools-2.2.31-1.8.amzn1.x86_64
[stderr]Error: httpd24 conflicts with httpd-2.2.31-1.8.amzn1.x86_64
[stdout] You could try using --skip-broken to work around the problem
[stdout] You could try running: rpm -Va --nofiles --nodigest

Anyone what is the problem?

hkguile
  • 4,235
  • 17
  • 68
  • 139

4 Answers4

5

The error code HEALTH_CONSTRAINTS means more instances failed than expected, which is defined by the deployment configuration.

For more information about why the deployment failed, on the deployment console https://region.console.aws.amazon.com/codedeploy/home?region=region#/deployments, you can click on the failed deploymentID, then it will redirect to the deployment details page, which contains all of the instances included in the specified deployment, and each line contains the instance's lifecycle event. Then click on the ViewEvents, then if there is View Logs link, you can see the reason why this instance deployment failed.

If the console doesn't have enough information for what you need, then the log on the instance can be found at less /var/log/aws/codedeploy-agent/codedeploy-agent.log. It contains the logs for most recent deployments.

binbinlu
  • 416
  • 2
  • 5
  • 1
    i've found error in log: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Missing credentials - please check if this instance was started with an IAM instance profile – hkguile Aug 05 '16 at 02:05
  • That would do it also. None of your deployments succeeded since you have no permissions to deploy to them... they all failed. – Rodrigo Murillo Aug 06 '16 at 18:28
  • how to give this permission? I attached IAM role ec2-s3-fullaccess still it's failing – Ashish Karpe Jun 12 '18 at 10:59
  • changed Deployment configuration to CodeDeployDefault.AllAtOnce from CodeDeployDefault.OneAtTime now it's working – Ashish Karpe Jun 12 '18 at 11:42
1

This happens because the codeDeploy checks health of the ec2 instances by hitting instances. Before deployment, you need to run below bash script on the instances and check if the script worked. httpd service must be started. Reboot the instance.

    #!/bin/bash
    sudo su
    yum update -y
    yum install httpd -y
    yum install ruby
    yum install aws-cli
    cd ~
    aws s3 cp s3://aws-codedeploy-us-east-1/latest/install . --region us-east-1
    chmod +x ./install
    ./install auto
    echo 'hello world' > /var/www/html/index.html
    hostname >> /var/www/html/index.html
    chkconfig httpd on
    service httpd start
harsh tibrewal
  • 785
  • 6
  • 21
0

It depends on your deployment configuration, but basically 1 or more deployments failed.

HEALTH_CONSTRAINTS: The deployment failed on too many instances to be successfully deployed within the instance health constraints specified

http://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ErrorInformation.html

Check your deployment configuration settings. The overall failure/success of the deployment is based on these settings. Try the CodeDeployDefault.AllAtOnce, and dial in as needed.

Also, double check AWS CodeDeploy Instance Health settings, especially minimum-healthy-hosts

Rodrigo Murillo
  • 13,080
  • 2
  • 29
  • 50
0

It seems there is a conflict between one of the dependencies you asked to install in your appspec.yaml file and your httpd24-tools service.

[stderr]Error: httpd24-tools conflicts with httpd-tools-2.2.31-1.8.amzn1.x86_64
[stderr]Error: httpd24 conflicts with httpd-2.2.31-1.8.amzn1.x86_64
[stdout] You could try using --skip-broken to work around the problem

So try to solve the dependency installation problem. You can try to install dependencies manually on your ec2 and find a solution for this conflict and when you solved it bring the solution to your appspec.yaml file and install the dependencies via code deploy.

Iman Sedighi
  • 7,624
  • 4
  • 48
  • 55