Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

76장. EventBridge — 이벤트 기반 아키텍처

이 장에서 말하고자 하는 것

SNS가 단순 팬아웃이라면
EventBridge는 한 단계 더 풍부한 이벤트 버스 다.

Amazon EventBridge

EventBridge는 다음을 한 곳에서 다룬다.

  • 내 애플리케이션 이벤트
  • AWS 서비스 자체 이벤트 (예: EC2 상태 변경)
  • 서드파티 SaaS 이벤트 (Datadog, Zendesk, Shopify 등)

복잡한 라우팅과 스키마 관리를 더해서.


1. 기본 모델 — Event Bus + Rule + Target

[Publisher]
   ↓ PutEvents
[Event Bus]
   ↓
[Rule 1: type=OrderCreated]    → SQS · Lambda · ECS · Step Functions
[Rule 2: type=PaymentFailed]   → SNS · email
[Rule 3: source=aws.ec2]        → CloudWatch / Lambda
  • 이벤트는 Event Bus로 보낸다
  • Rule이 이벤트 패턴을 매칭해 Target으로 보낸다
  • 한 이벤트가 여러 Rule에 매칭될 수 있다

2. 이벤트 패턴 — JSON 매칭

{
  "source": ["myapp.orders"],
  "detail-type": ["OrderCreated"],
  "detail": {
    "amount": [{ "numeric": [">", 100000] }]
  }
}
  • source · detail-type · detail 의 값을 매칭
  • 숫자 · 접두사 · IP · anything-but 같은 풍부한 연산자 지원

SNS의 필터 정책보다 표현력이 훨씬 크다


3. 다양한 Target

EventBridge가 보낼 수 있는 곳이 매우 많다.

Lambda
SQS
SNS
ECS Task 실행 (RunTask)
Step Functions
Kinesis
EventBridge Pipes
다른 계정의 Event Bus
HTTPS API (API Destinations)

특히

다른 계정의 Event Bus 로 이벤트를 보낼 수 있다

가 멀티 계정 운영에서 강력하다.


4. AWS 서비스 이벤트 자동 수신

EventBridge에는 “default” 이벤트 버스가 있다.

EC2 인스턴스 상태 변경
S3 객체 생성
RDS 백업 완료
CodePipeline 단계 변경
Health Dashboard 알림
... 등 거의 모든 AWS 서비스의 이벤트

이 이벤트를 자동으로 받아서 처리할 수 있다.

"운영 RDS에 백업이 실패하면 → Slack 알림"
"S3에 파일이 업로드되면 → Lambda 처리"
"보안 그룹이 변경되면 → 알람"

5. EventBridge Pipes — 단순 연결

큐 → 변환 → 또 다른 큐 같은 직선 흐름을 코드 없이 구성.

[SQS] → [Filter] → [Enrichment(Lambda)] → [SNS]

ETL 같은 작은 연결을 Pipes 로 풀 수 있다.


6. Schema Registry

이벤트의 스키마를 등록해 관리할 수 있다.

  • 발행자/구독자가 같은 스키마를 보고 있는지 확인
  • 코드 생성기로 클라이언트 SDK 자동 생성
  • AWS 자체 이벤트 스키마도 자동 발견

큰 조직에서 이벤트 계약을 관리할 때 핵심 도구


7. SNS vs EventBridge — 다시

항목SNSEventBridge
라우팅토픽 + 필터 정책Rule + 풍부한 패턴
Target 다양성SQS · Lambda · HTTPS · email · SMS거의 모든 AWS 서비스 + 외부
AWS 서비스 이벤트
서드파티 SaaS
스키마 관리
성능매우 빠름빠름 (SNS보다 약간 늦음)
비용가장 쌈약간 비쌈

단순 fan-out → SNS
라우팅 · AWS/SaaS 통합 · 스키마 관리 → EventBridge


8. 우리 서비스에서

[orders 서비스]
   ↓ PutEvents
[EventBridge: msa-bus]
   ├─ Rule "high-value": detail.amount > 1,000,000
   │     → Step Functions (VIP 처리 워크플로우)
   ├─ Rule "all-orders":
   │     → SQS (analytics-jobs)
   │     → SQS (notification-jobs)
   └─ Rule "cancel":  detail-type = OrderCancelled
         → Lambda (환불 처리)

(추가로)
default 버스
  ├─ S3 객체 업로드 → Lambda (썸네일)
  └─ RDS 백업 실패 → SNS (Slack)

내부 도메인 이벤트는 msa-bus, AWS 시스템 이벤트는 default 버스.


9. 직접 확인해보기 — CLI

Event Bus + Rule + Target

aws events create-event-bus --name msa-bus

aws events put-rule \
  --event-bus-name msa-bus \
  --name high-value-orders \
  --event-pattern '{
    "source": ["myapp.orders"],
    "detail-type": ["OrderCreated"],
    "detail": { "amount": [{ "numeric": [">", 1000000] }] }
  }'

aws events put-targets \
  --event-bus-name msa-bus \
  --rule high-value-orders \
  --targets '[{"Id":"1","Arn":"<step-functions-arn>","RoleArn":"<role-arn>"}]'

이벤트 발행

aws events put-events --entries '[{
  "EventBusName": "msa-bus",
  "Source": "myapp.orders",
  "DetailType": "OrderCreated",
  "Detail": "{\"orderId\":\"o-1\",\"amount\":1500000}"
}]'

10. 코드로는 이렇게 생겼다 — Terraform

resource "aws_cloudwatch_event_bus" "msa" {
  name = "msa-bus"
}

resource "aws_cloudwatch_event_rule" "high_value" {
  name           = "high-value-orders"
  event_bus_name = aws_cloudwatch_event_bus.msa.name

  event_pattern = jsonencode({
    source        = ["myapp.orders"]
    "detail-type" = ["OrderCreated"]
    detail = {
      amount = [{ numeric = [">", 1000000] }]
    }
  })
}

resource "aws_cloudwatch_event_target" "high_value_sqs" {
  event_bus_name = aws_cloudwatch_event_bus.msa.name
  rule           = aws_cloudwatch_event_rule.high_value.name
  arn            = aws_sqs_queue.vip_jobs.arn
}

11. 이렇게 쓰면 망한다 — 안티패턴

안티패턴 1. 단순 fan-out 인데 EventBridge로 시작

SNS가 더 싸고 빠르다.

“라우팅” 이 진짜 필요할 때 EventBridge

안티패턴 2. 이벤트 스키마를 정의하지 않는다

Producer와 Consumer가 다른 모양을 가정 → 깨진다.

Schema Registry 또는 사내 문서로 계약을 명시

안티패턴 3. DLQ를 안 건다

EventBridge → SQS 같은 흐름도 실패 가능. DLQ로 격리한다.

안티패턴 4. 한 이벤트 버스에 모든 도메인을 섞는다

권한 · 모니터링이 다 섞인다.

도메인/팀 단위로 Event Bus를 분리하는 게 큰 조직에서 자연스럽다


12. 한 줄로 정리

EventBridge는 라우팅 · AWS 이벤트 · 서드파티 통합 · 스키마 관리를 더한 이벤트 버스이며,
단순 팬아웃을 넘어서는 순간 등장한다


13. 이 장의 핵심 정리

  1. EventBridge는 Event Bus + Rule + Target 의 3축이다.
  2. 이벤트 패턴 매칭이 SNS 필터보다 표현력이 크다.
  3. AWS 서비스 자체 이벤트와 서드파티 SaaS를 자연스럽게 받는다.
  4. Target은 Lambda · SQS · ECS · Step Functions · 다른 계정 등 매우 다양하다.
  5. 단순 팬아웃은 SNS, 라우팅·통합·스키마는 EventBridge.
  6. Schema Registry는 큰 조직에서 이벤트 계약을 관리하는 핵심 도구다.