CodeDeploy agent was not able to receive the lifecycle event. Check the CodeDeploy agent logs on your host and make sure the agent is running and can connect to the CodeDeploy server.

codedeploy 에서 발생하는 오류로 배포 목록에서 배포 ID를 누르면 아래처럼 오류 메시지가 나온다.

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.

사실 위 에러 메시지를 보고는 정확히 알수 없다.

'배포 수명 주기 이벤트' 안에서 실패 이벤트를 찾아서 보면 ApplicationStop 에서 아래 오류가 뜬다.

CodeDeploy agent was not able to receive the lifecycle event. Check the CodeDeploy agent logs on your host and make sure the agent is running and can connect to the CodeDeploy server.

위 이미지를 보면 이벤트가 ApplicationStop에서 오류로 남아있다.

이 오류의 원인과 해결 방법은 여러개가 나오기 때문에 이 부분 가지고는 명확한 원인을 알 수 없다.
그렇기 때문에 codedeploy의 에러 로그를 열어본다.

vi /var/log/aws/codedeploy-agent/codedeploy-agent.log

shift+g를 눌러 맨 마지막 이벤트를 확인한다.


오류 사례 1.

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

command_status 는 "Failed" 이고 메시지는 The CodeDeploy agent did not find an AppSpec file within the unpacked revision directory at revision-relative path \\\"appspec.yml\\\" 라고 appspec 파일이 없다고 한다.

그리고 경로 또한 The revision was unpacked to directory \\\"/opt/codedeploy-agent/deployment-root/4e99ad78-cd83-4478-b77e-7b88a5316899/d-15G5YDN51/deployment-archive 라면서 보여주는데 d-15G5YDN51 이 배포 아이디는 배포 시도한 배포 ID가 아니라 예전에 배포했던 배포 ID이다.

즉, 아무리 배포해도 예전 배포ID를 진행시키는 상황이다.

내가 해결을 위해 시도한 방법은 1. codedeploy 를 재시작한다. 2. codedeploy 에이전트를 다시 설치한다. 3. 인스턴스를 중지했다 다시 시작한다. 이렇게 3개 방법인데 해결되지 않았다. ❌

해결 방법.

🙏 결국 알아낸 건 /opt/codedeploy-agent/deployment-root/deployment-instructions 안에 배포되었던 파일들에 대한 정보들이 있는데 이 폴더를 deployment-instructions_backup 으로 변경하고 새로 배포하니 정상적으로 배포되었다. (그냥 삭제하면 무슨일이 생길지 모르니 백업!)

다시 배포하면 이렇게 새롭게 deployment-instructions 폴더가 생성되고 배포가 정상적으로 이루어 진다.

권장하는 방법은 아니라고 하지만 덕분에 이 글을 보고 해결했다. https://stackoverflow.com/a/64764997

찾아보니 ignore Application Stop Failures 를 설정해 놓고 배포하면 된다지만 직접 cli로 했던 github workflow에서는 create-deployment 할 때 옵션을 --ignore-application-stop-failures으로 줄 수 있지만 codepipeline 에서는 설정이 불가능하다.

그나마 가능한 건 cicd가 아닌 직접 배포 생성해서 배포할 때 아래 이미지처럼 옵션이 있어서 가능하긴 하지만 자동화로는 설정할 수 있는 곳이 없다. (아직 내가 못찾은 걸 수도 있다.)

덕분에 오래전부터 묵혀있던 원인 불명의 codedeploy 오류를 해결했다. 😮‍💨


오류 사례 2.

Missing credentials - please check if this instance was started with an IAM instance profile

해당 ec2 인스턴스의 IAM 역할이 빠져 있을 수 있다.

해결 방법.

ec2에 IAM 을 추가한 뒤 아래 코드로 codedeploy agent를 재실행 하면 된다.

sudo service codedeploy-agent restart

Subscribe
Notify of
guest

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.

0 댓글
Inline Feedbacks
View all comments
TOP