Project/따숲

[따숲] CICD Pipeline 구축 (1) - IAM & Codedeploy 설정

예림밈 2025. 6. 16. 18:40
728x90

 

 CICD 파이프라인 구축 과정을 상세히 적어보려고 한다. ⭐️

 

 

CICD Pipeline 구축 과정

 (1) GitHub에 적용할 IAM User & Role 생성

1. Github push IAM 권한 User 생성

aws iam create-user --user-name ttasup-user-github

 

2. IAM User 정책 할당 명령어 생성

aws iam attach-user-policy --user-name ttasup-user-github --policy-arn arn:aws:iam::aws:policy/AWSCodeDeployFullAccess

 

3. 할당된 정책 확인 명령어

aws iam list-attached-user-policies --user-name ttasup-user-github

 

4. GitHub용 Access Key / Secret key 생성

  • 콘솔에서 생성해도 되지만, 터미널로 생성 가능하다. 
aws iam create-access-key --user-name ttasup-user-github > ~/.ssh/access_key.json

 

 

 (2) AWS CodeDeploy에 적용할 IAM User & Role 생성

1.CodeDeploy용 IAM Role 생성 

aws iam create-role --role-name ttasup-role-codedeploy --assume-role-policy-document file://support_files/policy/codedeploy_trust_policy.json

 

2. IAM Role에 정책 할당 명령어 실행

aws iam attach-role-policy --role-name ttasup-codedeploy --policy-arn arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole

 

3. 할당된 정책 확인 명령어

aws iam list-attached-role-policies --role-name ttasup-role-codedeploy

 

 

 (3) Github Repository - AccessKey & SecretKey 등록

1. GitHub Repository 접속 → Settings 탭 → Secrets and variables 선택 → Actions 선택 → New repository secret 버튼 클릭

  • Access key 정보 입력 → Add secret 버튼 클릭
    • Name: AWS_ACCESS_KEY
    • Secret: [AWS_ACCESS_KEY_VALUE]
  • Secret key 정보 입력 → Add secret 버튼 클릭
    • Name: AWS_SECRET_KEY
    • Secret: [AWS_SECRET_KEY_VALUE]

 

(4) CodeDeploy 생성

1. CodeDeploy 콘솔 메인 화면 → 애플리케이션 탭 → 애플리케이션 생성 버튼 클릭

 

 

2. Application 생성 정보 입력

  • 애플리케이션 이름: test_cicd
  • 컴퓨팅 플랫폼: EC2/온프레미스

 

3. 배포 그룹 생성 버튼 클릭

 

  • 배포 그룹 생성 정보 입력
    • 배포 그룹 이름: test-cicd-deploygroup
    • 서비스 역할: ttasup-role-codedeploy

 

  • Amazon EC2 인스턴스 체크
    • 키: Name
    • 값: ttasup-ec2-web

 

  • 로드 밸런싱 활성화 체크 해제 → 배포 그룹 생성 버튼 클릭

 

 

(5) CodeDeploy Agent 설정

1. 관련 패키지 다운로드

sudo yum update -y && sudo yum install ruby -y && sudo yum install wget -y

 

2. CodeDeploy Agent 설치 프로그램 다운로드

wget https://aws-codedeploy-ap-northeast-2.s3.ap-northeast-2.amazonaws.com/latest/install

 

3. 설치 파일 실행 권한 할당

chmod +x ./install

 

4. CodeDeploy Agent 서비스 실행 및 상태 확인 명령

systemctl status codedeploy-agent   # sudo service codedeploy-agent status
systemctl start codedeploy-agent    # sudo service codedeploy-agent start