[Elastic Beanstalk] Environment still has health Grey 해결

준커·2023년 6월 1일
2

DevOps

목록 보기
2/6
post-thumbnail

Elastic Beanstalk 트러블 슈팅

환경

  • Elastic Beanstalk
  • Github Actions
  • Spring boot 2.7.9 + JAVA 11

Github Actions Workflow

name: CI CD with github actions and EB

on:
  push:
    branches: [ develop ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Latest Repo
        uses: actions/checkout@v2

      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          java-version: 11
          distribution: 'temurin'

      - name: Grant execute permission for gradlew
        run: chmod +x ./gradlew
        shell: bash

      - name: Build with Gradle
        run: ./gradlew clean build -Pprofile=dev
        shell: bash

      - name: Get current time
        uses: 1466587594/get-current-time@v2
        id: current-time
        with:
          format: YYYY-MM-DDTHH-mm-ss 
          utcOffset: "+09:00" 

      - name: Generate deployment package
        run: |
          mkdir -p deploy
          cp build/libs/*.jar deploy/application.jar
          cp Procfile deploy/Procfile
          cp -r .ebextensions deploy/.ebextensions
          cp -r .platform deploy/.platform
          cd deploy && zip -r deploy.zip .
        
      - name: Beanstalk Deploy
        uses: einaregilsson/beanstalk-deploy@v21
        with:
          aws_access_key: ${{ secrets.AWS_ACCESS_KEY }}
          aws_secret_key: ${{ secrets.AWS_SECRET_KEY }}
          application_name: OPPLA
          environment_name: OPPLA-env
          version_label: Github Action-${{steps.current-time.outputs.formattedTime}}
          region: ap-northeast-2
          deployment_package: deploy/deploy.zip
          wait_for_environment_recovery: 180

1. 트러블 발생

서버 배포 및 API 테스트엔 성공 했지만, Github Actions build엔 실패 했다!

  • CI/CD를 적용해 놓은 develop 브랜치에 push 후 배포에 성공하여, Swagger 페이지에 정상 접속되었다.

  • Swagger를 통한 API 테스트도 성공적으로 이루어졌다

  • 하지만 Github Actions의 build는 실패하였다.

  • build 내용을 보니 Beanstalk Deploy에서 실패한 것을 확인할 수 있었다.

Warning: Environment update finished, but health is Grey and health status is No Data. Giving it 180 seconds to recover...
Warning: Environment still has health: Grey and health status No Data. Waiting 169 more seconds before failing...
INFO: Environment health has transitioned from Info to No Data. Application update completed 52 seconds ago and took 65 seconds. None of the instances are sending data.
Error: Deployment failed: Error: Environment still has health Grey 180 seconds after update finished!
  • 에러원인은 Elastic Beanstalk이 하는 health check를 통과하지 못했다는 이유였다.

2. 원인

  • 네트워크 등 여러 가지 이유로 Elastic Beanstalk과의 통신 속도가 느려 문제가 없음에도, 제한 시간 안에 health check를 완료하지 못해 timeout이 났던 것이다.

3. 해결

- name: Beanstalk Deploy
        uses: einaregilsson/beanstalk-deploy@v21
        with:
          aws_access_key: ${{ secrets.AWS_ACCESS_KEY }}
          aws_secret_key: ${{ secrets.AWS_SECRET_KEY }}
          application_name: OPPLA
          environment_name: OPPLA-env
          version_label: Github Action-${{steps.current-time.outputs.formattedTime}}
          region: ap-northeast-2
          deployment_package: deploy/deploy.zip
          wait_for_environment_recovery: 180
  • 내가 작성한 Workflow 파일을 보면 제일 마지막 줄에 health check를 하는 시간을 늘려주는 코드가 있다.
wait_for_environment_recovery: 180
  • 이 부분을 설정하지 않으면 기본값은 30초로 지정된다고 한다. 하지만 내 경우엔 기본값 30초에서 180로 조정하였음에도 에러가 발생하였다.
wait_for_environment_recovery: 180
  • 해당 부분을 300초로 증가시켜 에러를 해결하였다.

profile
학부생일뿐

0개의 댓글