1. External ALB / External NLB / Internal ALB 리소스 배포

import * as aws from '@pulumi/aws'
import * as pulumi from '@pulumi/pulumi'

export interface HealthCheckOpts {
  path: string
  healthyThreshold: number
  unhealthyThreshold: number
  interval: number
  timeout: number
  matcher: string
  protocol: string
}

interface RoomSocket2Args {
  vpcId: pulumi.Output<string>
  external: {
    application: {
      httpsListener: aws.lb.Listener
    }
  }
}

export class Socket extends pulumi.ComponentResource {
  constructor(args: Socket, opts: pulumi.ComponentResourceOptions) {
    super('socket', 'root', {}, opts)

    const healthCheckOpts: HealthCheckOpts = {
      path: '/api/v1.0/socket/health', 
      healthyThreshold: 2,
      unhealthyThreshold: 2,
      interval: 10,
      timeout: 2,
      matcher: '200',
      protocol: 'HTTP',
    }

    const targetGroup = new aws.alb.TargetGroup(
      'ex', 
      {
        healthCheck: healthCheckOpts,
        deregistrationDelay: 10,
        targetType: 'ip',
        name: 'dev-ex-socket', 
        port: 5000, 
        protocol: 'HTTP',
        protocolVersion: 'HTTP1',
        vpcId: args.vpcId,
      },
      {
        ...opts,
        parent: this,
      }
    )

    new aws.alb.ListenerRule(
      'ex',
      {
        listenerArn: args.external.application.httpsListener.arn,
        priority:
          ListenerRulePriority.EXTERNAL_ALB.HTTPS.ROOM_SOCKET.priority,
        actions: [
          {
            type: 'forward',
            forward: {
              targetGroups: [
                {
                  arn: targetGroup.arn,
                  weight: 100,
                },
              ],
            },
          },
        ],
        conditions: [
          {
            hostHeader: {
              values: ['dev-hyunji-api.hyunjicompany.co.kr'], 
            },
          },
          {
            pathPattern: {
              values: ['/api/v1.0/socket', '/api/v1.0/socket/*'], 
            },
          },
        ],
      },
      {
        ...opts,
        parent: this,
      }
    )
  }
}

Target Group


  healthCheck: {
    enabled: true,
    path: '/health',           // 어떤 경로로 확인? (예: GET /health)
    protocol: 'HTTP',          // 어떤 프로토콜로?
    interval: 30,              // 몇 초마다? (30초마다)
    timeout: 5,                // 몇 초 안에 응답 없으면 실패? (5초)
    healthyThreshold: 2,       // 몇 번 성공하면 healthy? (2번 연속 성공)
    unhealthyThreshold: 2,     // 몇 번 실패하면 unhealthy? (2번 연속 실패)
    matcher: '200'             // 어떤 응답 코드가 정상? (200 OK)
  }

    const targetGroup = new aws.alb.TargetGroup(
      'ex',
      {
        healthCheck: healthCheckOpts,
        deregistrationDelay: 10,
        targetType: 'ip', // 서버를 IP 주소로 식별
        name: 'dev-room-socket-api', 
        port: 5000, // room-socket 앱이 5000번 포트에서 대기 중
        protocol: 'HTTP', // ALB가 서버와 HTTP로 통신
        protocolVersion: 'HTTP1',
        vpcId: args.vpcId,
      },
      {
        ...opts,
        parent: this,
      }
    )

Target group의 protocol version options

Listener 타입

1. HTTP Listener (포트 80)

2. HTTPS Listener (포트 443)