본문 바로가기

AWS

[AWS Elastic Beanstalk] health check error

1. health check 하는 이유

헬스 체크는 생성 된 ec2 인스턴스가 정상적인 상태인지 확인하기 위해 한다. 이러한 체크는 필수적으로 이루어져야 한다. 그래야 해당하는 인스턴스가 정상적인 상태인지 알 수가 있다.

 

2. 문제점

  • AWS EB는 default로 '/' url을 보내 정상적으로 통신이 가능한지 확인을 자동적으로 해준다. 그래서 해당 경로를 처리하는 api를 만들어주지 않으면 EB가 정상적으로 작동하지 않는다.

3. 해결책

import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class CheckController {
    @Value("\${spring.config.activate.on-profile}")
    val profile: String? = null

    @RequestMapping(value = ["/health", "/"])
    fun healthCheck(): ResponseEntity<String> {
        return ResponseEntity("Spring Boot api-server application($profile)", HttpStatus.OK)
    }
}
  • 이렇게 해당 경로를 처리하는 api를 만들어주면 EB health check를 정상적으로 통과할 수 있다.

 

3. AWS EB 커스텀 설정

 

 

EB 환경 > 구성 > 로드 밸런서 편집

 

로드 밸런서 > 프로세스 > 작업 > 편집

  • 상태 검사 경로를 저렇게 직접 설정해줘도 된다.

 

 

references

https://docs.aws.amazon.com/ko_kr/elasticbeanstalk/latest/dg/using-features.healthstatus.html

https://docs.aws.amazon.com/ko_kr/elasticbeanstalk/latest/dg/environments-cfg-clb.html#using-features.managing.elb.healthchecks

https://discourse.metabase.com/t/aws-eb-setup-failing-due-to-health-check/55