CICD

[Devops] Github Action + AWS Code Deploy 트러블슈팅

예림밈 2025. 6. 12. 19:59
728x90

 

Github Action과 AWS Code Deploy를 활용한 CICD를 진행하면서 생긴 오류를 적어보려고 한다. 

 

 

💡 이슈 1. Github Actions Deploy 가 잘 되었는지 확인하려고 AWS CodeDeploy 확인했는데 다음과 같이 실패했다. 

 

** 로그 보는 명령어 

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

 

 

에러 내용:  로그를 보니 EC2에 IAM 권한(Deploy권한)이 없어서였다. 

2025-06-12T03:20:07 ERROR [codedeploy-agent(2624)]:
InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Missing credentials 
- please check if this instance was started with an IAM instance profile

 

해결책 : EC2에 IAM 역할 생성 후 연결해주면 된다. 

 

 

 

💡 이슈 2. CodeDeploy가 GitHub에서 배포용 번들(코드 패키지)을 다운로드하려고 했는데, 요청한 URL에서 404 Not Found가 떴다.
InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor: 
Could not download bundle at 'https://api.github.com/repos/EomYerim/CICD_TEST/tarball/'. 
Server returned code 404 'Not Found'

 

해결 방안 : 생각해보니, Github 레포지토리가 Private으로 되어 있어서 접근을 할 수 없었던 것이었다.. Public으로 바꿔주니 성공!

 

 

💡 이슈 3. 배포 대상 패키지 내에 appspec.yml 파일이 없어서 배포가 되지 않았다. 
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/…/deployment-archive",
and the AppSpec file was expected but not found at path "/opt/codedeploy-agent/deployment-root/…/deployment-archive/appspec.yml".

 

** AppSpec.yml 파일AWS CodeDeploy에서 배포를 정의하는 핵심 설정 파일

나는, 기본 테스트만 하기 위해 자바 설치 스크립트만 간략히 짰다. 

 

1. 프로젝트 구조

최상위

  • appspec.yml

scripts 폴더

  • after_install.sh
  • before_install.sh
  • start.sh

 

 

appspec.yml

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/app
    overwrite: yes

hooks:
  BeforeInstall:
    - location: scripts/before_install.sh
      timeout: 300
      runas: ubuntu

  AfterInstall:
    - location: scripts/after_install.sh
      timeout: 300
      runas: ubuntu

  ApplicationStart:
    - location: scripts/start.sh
      timeout: 300
      runas: ubuntu

 

 

before_install.sh

#!/bin/bash
echo "[BeforeInstall] 디렉토리 생성"
mkdir -p /home/ubuntu/app

 

after_install.sh

#!/bin/bash
echo "[AfterInstall] Java 설치 시작"
sudo apt update
sudo apt install -y default-jdk
java -version

 

 

start.sh

#!/bin/bash
echo "[ApplicationStart] 자바 설치 테스트 완료"
echo "배포 테스트 종료"

 

결과 🔥

성공!