Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS code deploy + bitbucket = failed (Error code HEALTH_CONSTRAINTS)

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?

like image 672
hkguile Avatar asked Aug 04 '16 08:08

hkguile


2 Answers

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.

like image 74
binbinlu Avatar answered Oct 01 '22 23:10

binbinlu


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
like image 21
harsh tibrewal Avatar answered Oct 01 '22 21:10

harsh tibrewal