AWS EventBridge는 SaaS 애플리케이션, AWS 서비스, 사용자 정의 애플리케이션의 이벤트를 연결하는 서버리스 이벤트 버스다. 200개 이상의 AWS 서비스에서 이벤트를 기본 수신한다.
EventBridge 구성 요소
| 구성 요소 | 설명 |
|---|
| 이벤트 버스 | 이벤트 수신 채널 (기본/커스텀/파트너) |
| 이벤트 패턴 | 라우팅 조건 정의 |
| 규칙(Rule) | 패턴-대상 매핑 |
| 대상(Target) | Lambda, SQS, SNS, Step Functions 등 |
| 아카이브 | 이벤트 재생 가능 저장 |
| 스케줄러 | cron/rate 표현식 스케줄링 |
커스텀 이벤트 발행
python
import boto3
import json
from datetime import datetime
events = boto3.client('events', region_name='ap-northeast-2')
# 이벤트 발행
events.put_events(
Entries=[{
'Source': 'com.mycompany.orders',
'DetailType': 'OrderPlaced',
'Detail': json.dumps({
'orderId': 'ORD-001',
'customerId': 'CUST-123',
'amount': 99.99,
'items': [{'productId': 'PROD-A', 'qty': 2}],
}),
'EventBusName': 'my-app-bus',
'Time': datetime.now(),
}]
)
이벤트 패턴 예시 (규칙)
json
{
"source": ["com.mycompany.orders"],
"detail-type": ["OrderPlaced"],
"detail": {
"amount": [{"numeric": [">", 100]}],
"items": {
"productId": ["PROD-A", "PROD-B"]
}
}
}
hcl
resource "aws_cloudwatch_event_rule" "order_placed" {
name = "order-placed-rule"
event_bus_name = aws_cloudwatch_event_bus.app_bus.name
event_pattern = jsonencode({
source = ["com.mycompany.orders"]
detail-type = ["OrderPlaced"]
})
}
resource "aws_cloudwatch_event_target" "process_order" {
rule = aws_cloudwatch_event_rule.order_placed.name
event_bus_name = aws_cloudwatch_event_bus.app_bus.name
arn = aws_lambda_function.process_order.arn
role_arn = aws_iam_role.eventbridge_role.arn
}
EventBridge Pipes (직접 연결)
EventBridge Pipes는 소스(SQS, Kinesis, DynamoDB Streams)를 필터링/변환하여 대상에 직접 연결하는 점-대-점 통합이다. Lambda 없이 이벤트 라우팅이 가능하다.