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
- HTTP1 :
- 요청당 하나의 연결
- 순차적 처리
- 대부분의 앱이 사용
- HTTP2 :
- 하나의 연결로 여러 요청 동시 처리
- 헤더 압축
- 더 빠름
- GRPC :
- Google의 RPC 프레임워크
- Protocol Buffers 사용
Listener 타입
1. HTTP Listener (포트 80)
- 암호화되지 않은 HTTP 트래픽 처리
- 평문 통신
- SSL/TLS 인증서 불필요
- Path 기반, Host 기반 라우팅 가능
2. HTTPS Listener (포트 443)
- SSL/TLS로 암호화된 트래픽 처리
- 보안 통신 (SSL/TLS 인증서 필수 - ACM에서 발급)
- ALB가 SSL termination 수행 (복호화 후 백엔드로 전달)
- HTTP와 동일한 라우팅 규칙 사용 가능