-
[CodePipeline]Unable to access the artifact with Amazon S3 object key인프라/aws 2024. 3. 19. 04:11
Code Pipeline으로 CI/CD 구축하던 중 Deploy stage에서 발생한 에러입니다.
이 에러를 이해하려면 기본적으로 Code pipeline의 각 stage 간에 결과물을 s3를 사용해서 공유한다는 것을 기억해야합니다.
[에러 해결을 위한 체크 리스트]
1. Build stage에서 s3에 artifacts를 남기고 있는가?
2. EC2에서 해당 버킷에 접근할 수 있는 권한을 가지고 있는가?
3. Code Deploy에서 소스코드를 받을 수 있는가? ( Code Deploy에서 소스코드를 사용해야한다면 )
저 같은 경우에는 CodeBuild에서 ECR로 push 를 하는 상황이라 빌드의 결과물이 없기 때문에 s3에 artifacts를 업로드 하지않은 것이 이 에러 발생의 원인이었습니다.
문제는 크게 2가지 였습니다.
1. build stage에서 s3에 artifacts를 남기지 않는다.
다음 stage인 deploy stage가 이전 stage가 남긴 결과물을 s3에서 찾지만 찾을 수 없기 때문에 Unable to access 라고 message를 줍니다.
2. deploy stage에서 필요한 것은 소스코드 였습니다.
필요한 것이 artifacts라고 생각하고 무의미한 txt 파일을 생성해서 artifacts로 남겼으나, Code Deploy가 필요로하는 소스코드가 전달되지 않았기 때문에, 에러는 발생하지 않았으나 원하는 동작이 실행되지 않았습니다.
해결을 위해 적용한 방법은 3가지 입니다.
1. build project를 수정해서 artifacts를 s3에 남긴다.
2. buildspec.yml을 수정해서 source stage에서 넘겨받은 모든 소스 코드를 artifacts로 남긴다.
// buildspec.yml artifacts: files: - '**/*'
3. CodeDeploy가 실행되는 EC2에서 S3에 접근할 수 있는 권한을 부여한다.
감사합니다.
[참고]
'인프라 > aws' 카테고리의 다른 글
보조 계정으로 ECR에서 Push / Pull 하기 (0) 2024.04.10 내가 보려고 만든 CodePipeline 구축 A to Z (0) 2024.03.23 CodePipeline으로 CI/CD 구축하기 (0) 2024.03.19 CodeDepoly로 EC2에 배포하기 (2) 2024.03.18 CodeBuild로 ECR 갱신하기 (0) 2024.03.18