Configure AWS ALB Target Group and Health Check Mechanism

Configure AWS ALB Target Group and Health Check Mechanism

  1. First, create a target group from the applicationListener using the .addTargets method with an ID of ProductsServiceAlbTarget:
applicationListener.addTargets("ProductsServiceAlbTarget",
       AddApplicationTargetsProps.builder()
           .build()
   );

Architect

  1. Set the target group name to productsServiceAlb:
.targetGroupName("productsServiceAlb")

Architect

  1. Next, specify port 8081 for the Load Balancer to send traffic to, using the HTTP protocol to communicate with the targets:
.port(8081)
.protocol(ApplicationProtocol.HTTP)

Architect

  1. Next, add the list of Fargate services to the target group:
.targets(Collections.singletonList(fargateService))

Architect

  1. Next, define the deregistration delay of 30 seconds, allowing the Load Balancer to wait before deregistering an unavailable target:
.deregistrationDelay(Duration.seconds(30))

Architect

  1. Next, configure the health check and enable health check to ensure that targets are operating correctly:
.healthCheck(HealthCheck.builder()
       .enabled(true)
       .build())

Architect

  1. Kế tiếp chúng ta sẽ cấu hình khoảng thời gian giữa các lần kiểm tra sức khỏe là 30 giây và thời gian tối đa để chờ đợi phản hồi từ một target trong mỗi lần kiểm tra là 10 giây
.interval(Duration.seconds(30))
.timeout(Duration.seconds(10))

Architect

  1. Finally, declare the endpoint used to check the health of targets as /actuator/health with port 8081 used in the health check to communicate with targets:
    .path("/actuator/health")
    .port(8081)
    

Architect