본문 바로가기
Etc/경험담

[AWS] Code Deploy

by 생각하는달팽이 2016. 5. 10.

안녕하세요?


이번 시간에는 Code Deploy  를 이용하여 코드 배포를 셋팅하였습니다.

bitbucket 과 AWS Code Deploy 를 연동하는 방식입니다.


만일 연동 후


Deployment Details

No hosts succeeded. (Error code: HEALTH_CONSTRAINTS) 

와 같은 문구를 보시게 된다면.

1. Security Group 확인
2. 해당 ec2 인스턴스에 aws-code-deploy-agent 가 설치 되어 있는지 확인

위의 두가지를 확인해 보시면 해결이 됩니다 :)

이상입니다.



이때 aws-code-deploy-agent 설치시 ruby 가 필요합니다.


루비 버전은 2.0.0 으로 설치해주셔야 합니다.


rvm 을 이용해 설치 하신후


해당 폴더 내의 bin 폴더에 들어가시면 install 실행파일이 있습니다.


rvmsudo ./install auto 


명령어를 입력해주세요 :)



보다더 쉬운 방법이 있습니다. 


== Ubuntu 14.04 LTS 기준 ==

아래는 aws 에서 참고해왔습니다. ( http://docs.aws.amazon.com/codedeploy/latest/userguide/how-to-run-agent-install.html )

sudo apt-get update
sudo apt-get install python-pip
sudo apt-get install ruby2.0
sudo apt-get install wget
cd /home/ubuntu
wget https://bucket-name.s3.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto

Type y if prompted.

bucket-name represents one of the following:

  • aws-codedeploy-us-east-1 for instances in the US East (N. Virginia) region

  • aws-codedeploy-us-west-1 for instances in the US West (N. California) region

  • aws-codedeploy-us-west-2 for instances in the US West (Oregon) region

  • aws-codedeploy-ap-south-1 for instances in the Asia Pacific (Mumbai) region

  • aws-codedeploy-ap-northeast-2 for instances in the Asia Pacific (Seoul) region

  • aws-codedeploy-ap-southeast-1 for instances in the Asia Pacific (Singapore) region

  • aws-codedeploy-ap-southeast-2 for instances in the Asia Pacific (Sydney) region

  • aws-codedeploy-ap-northeast-1 for instances in the Asia Pacific (Tokyo) region

  • aws-codedeploy-eu-central-1 for instances in the EU (Frankfurt) region

  • aws-codedeploy-eu-west-1 for instances in the EU (Ireland) region

  • aws-codedeploy-sa-east-1 for instances in the South America (São Paulo) region

region-name represents one of the following:

  • us-east-1 for instances in the US East (N. Virginia) region

  • us-west-1 for instances in the US West (N. California) region

  • us-west-2 for instances in the US West (Oregon) region

  • ap-south-1 for instances in the Asia Pacific (Mumbai) region

  • ap-northeast-2 for instances in the Asia Pacific (Seoul) region

  • ap-southeast-1 for instances in the Asia Pacific (Singapore) region

  • ap-southeast-2 for instances in the Asia Pacific (Sydney) region

  • ap-northeast-1 for instances in the Asia Pacific (Tokyo) region

  • eu-central-1 for instances in the EU (Frankfurt) region

  • eu-west-1 for instances in the EU (Ireland) region

  • sa-east-1 for instances in the South America (São Paulo) region





추가 에러입니다.


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)



저의 경우 VPC, ELB, ASG 에 적용을 하면서 발견한 에러입니다.


agent-log 에서도 나오지 않습니다. (_ _)


해결책


1. security group outbound 443 오픈되어 있는지 체크

2. health check 가 InService 인지 체크

3. 모두 정상인데 안된다면, 현재 사용중인 Instance 의 /home/ubuntu/ 이하 디렉토리 및 파일을 "sudo rm -rf" 깨끗이 제거. ( 이러면 처음 인스턴스 생성시와 동일하겠죠 ? ) - 서버 설정 및 여러가지 util 은 이미 해당 인스턴스에 설치가 되어 있습니다.

 이후 Image 를 만들어 줍니다. 이를 Empty Setup Instance 라고 부르겠습니다. 약칭 ESI 라고 부르겠습니다.

해당 ESI 를 ELB ( 로드밸런싱서비스 ) 에 등록해주시고요. 오토스케일그룹을 설정해줍니다. 이제 준비는 끝났습니다.

소스를 deploy 해줍니다. 



 저의 경우 3번의 해결책으로 해결이 됐습니다.



Code Deploy 설정시 잊지 말아야할 것은.



IAM Role 설정을 올바르게 해주셔야합니다.


1. Policy.

- CodeDeploy Access Role

- EC2 Access Role

- S3 Access Role 


세가지 정책에 대한 Permission 이 있어야 했습니다.


2. Trustration Policy

- 저의 경우 third party application ( bitbucket ) 을 이용하였기에. 해당 App id 와 External id 를 추가로 승인해주었습니다. 기본적으로는


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



아래의 정책을 넣어주시면 된다고 합니다 (  AWS 문서에 명시되어 있습니다. )


반응형

'Etc > 경험담' 카테고리의 다른 글

[Unity] AssetBundle 시스템 구축  (3) 2016.05.23
[Pod] Xcode 오픈 소스 사용시 Pod  (0) 2016.05.12
[AWS] 인프라 구축  (0) 2016.04.06
[AWS] LB,Auto-scale group  (0) 2016.04.01
[MySQL] Replication 장애 복구  (0) 2016.03.02