포스트

AWS CodeDeploy Issue - 배포 중 BeforeInstall 단계에서 보류 되다가 실패

발생한 상황

BeforeInstall 단계에서 보류 되다가 실패로 전환됨 image image


원인 찾기

web console 로그 확인

image

1
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.


code deploy agent 로그 확인

code deploy agent 로그 위치 (ubuntu 기준)

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

실패 메세지

(쾌적한 해석을 위해 https://jsonformatter.org을 통해 가공 후 추가)

1
2
3
4
5
6
{
  "error_code": 5,
  "script_name": "",
  "message": "The CodeDeploy agent did not find an AppSpec file within the unpacked revision directory at revision-relative path \"appspec.yml\". The revision was unpacked to directory \"/opt/codedeploy-agent/deployment-root/fc39dc40-7367-4df7-96c9-da1a8e43ea6f/d-ME0SB69H5/deployment-archive\", and the AppSpec file was expected but not found at path \"/opt/codedeploy-agent/deployment-root/fc39dc40-7367-4df7-96c9-da1a8e43ea6f/d-ME0SB69H5/deployment-archive/appspec.yml\". Consult the AWS CodeDeploy Appspec documentation for more information at http://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file.html",
  "log": ""
}

원인

appspec.yml 을 찾는데 이 파일이 없어서 fail 되었다.

내 경우 다양한 실습 중 파일을 보존하기 위한 방법으로 appspec.yml 이름을 변경했는데 이것 때문인 듯 했다.
(직전 이름 : appspec.yml, 이번 이름 : appspec-docker.yml)

appspec 파일 이름은 무조건 appspec.yml이어야 하는데 이 규칙을 지키지 않았기 때문에 codeDeploy가 파일을 찾지 못해 발생한 에러였다.


해결

github의 커밋 히스토리를 확인하지 않고 프로젝트에서 파일로써 다양한 appspec 파일을 관리하고 싶었기 때문에 appspec 파일 이름을 변경한 상태(appspec-docker.yml)로 유지하고 대신 github actions 실행 스크립트에서 appspec 파일을 s3로 보내기 전에 appspec.yml로 이름을 변경한 후 변경된 파일을 s3로 보내도록 수정하여 해결했다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
...
    
env:   
  APPSPEC_FILE_NAME: appspec-docker.yml
  
jobs:  
  deploy-with-aws-and-docker:  
    runs-on: ubuntu-latest  
    steps:
      - ...

      - name: appspec 이름 변경  
        run: sudo mv ./$APPSPEC_FILE_NAME ./appspec.yml  
        
      - name: 실행 파일 압축  
        run: tar -czvf $GITHUB_SHA.tar.gz appspec.yml scripts  
        
      - name: s3에 프로젝트 압축 파일 업로드  
        run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.tar.gz s3://$SERVER_NAME/$GITHUB_SHA.tar.gz
...


발생 원인 분석

공식 문서에 보면 로컬에 배포하는 경우를 제외하고는 appspec 파일 이름을 appspec.yml로 해야만 한다고 나와있는데 공식 문서를 확인하지 않고 진행하다가 이러한 상황을 마주하고 말았다. 처음 학습할 때 공식 문서를 읽어보는 습관을 갖도록 노력해보면 좋을 것 같다.,;

해당 사항 공식 문서 바로가기




📜 CodeDeploy 로그 위치 모음 (ubuntu)

  • CodeDeploy Agent 로그
    1
    
    /var/log/aws/codedeploy-agent/codedeploy-agent.log
    
  • CodeDeploy 배포 로그
    1
    
    /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log
    
  • CodeDeploy 스크립트 로그
    1
    
    /opt/codedeploy-agent/deployment-root/{deployment-group-ID}/{deployment-ID}/logs/scripts.log
    




참고한 사이트

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.