AWS SAA 실전 가이드 - 모니터링, 로깅, 옵저버빌리티 완벽 마스터
AWS SAA 실전 가이드 - 모니터링, 로깅, 옵저버빌리티 완벽 마스터
AWS Solutions Architect Associate(SAA) 시험에서 반드시 알아야 할 모니터링과 로깅 시스템을 완벽하게 마스터해보겠습니다. 실제 프로덕션 환경에서 사용되는 최적화된 옵저버빌리티 전략을 학습합니다.
🎯 목차
📊 CloudWatch 핵심 개념
1. 메트릭과 네임스페이스
기본 메트릭 vs 커스텀 메트릭
# AWS SDK를 통한 커스텀 메트릭 전송
import boto3
from datetime import datetime
cloudwatch = boto3.client('cloudwatch')
# 비즈니스 메트릭 전송
cloudwatch.put_metric_data(
Namespace='MyApp/Business',
MetricData=[
{
'MetricName': 'OrdersProcessed',
'Value': 150,
'Unit': 'Count',
'Timestamp': datetime.utcnow(),
'Dimensions': [
{
'Name': 'Environment',
'Value': 'Production'
}
]
}
]
)
2. 알람 설정 전략
스마트 알람 구성
# CloudFormation 템플릿
Resources:
HighCPUAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: EC2-High-CPU
AlarmDescription: EC2 인스턴스 CPU 사용률 80% 초과
MetricName: CPUUtilization
Namespace: AWS/EC2
Statistic: Average
Period: 300
EvaluationPeriods: 2
Threshold: 80
ComparisonOperator: GreaterThanThreshold
AlarmActions:
- !Ref SNSTopic
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
🔍 CloudTrail 보안 감사
1. 이벤트 로깅 전략
관리 이벤트 vs 데이터 이벤트
{
"eventTime": "2025-07-15T09:30:00Z",
"eventName": "PutObject",
"eventSource": "s3.amazonaws.com",
"userIdentity": {
"type": "AssumedRole",
"principalId": "AIDACKCEVSQ6C2EXAMPLE",
"arn": "arn:aws:sts::123456789012:assumed-role/S3-Role/user"
},
"requestParameters": {
"bucketName": "my-secure-bucket",
"key": "sensitive-data.txt"
},
"responseElements": {
"ETag": "\"d41d8cd98f00b204e9800998ecf8427e\""
}
}
2. 실시간 보안 모니터링
CloudWatch Events + Lambda 통합
import json
import boto3
def lambda_handler(event, context):
# CloudTrail 이벤트 파싱
detail = event['detail']
# 위험한 API 호출 감지
dangerous_apis = [
'DeleteBucket',
'PutBucketPolicy',
'CreateUser',
'AttachUserPolicy'
]
if detail['eventName'] in dangerous_apis:
# Slack 알림 전송
send_security_alert(detail)
return {
'statusCode': 200,
'body': json.dumps('Event processed')
}
def send_security_alert(event_detail):
# SNS를 통한 보안 팀 알림
sns = boto3.client('sns')
message = f"🚨 Security Alert: {event_detail['eventName']} by {event_detail['userIdentity']['arn']}"
sns.publish(
TopicArn='arn:aws:sns:us-east-1:123456789012:security-alerts',
Message=message,
Subject='AWS Security Alert'
)
🔬 X-Ray 분산 추적
1. 마이크로서비스 추적
Lambda 함수 X-Ray 설정
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all
# AWS SDK 자동 계측
patch_all()
@xray_recorder.capture('order_processing')
def process_order(order_data):
# 세그먼트 메타데이터 추가
xray_recorder.current_segment().put_metadata('order_id', order_data['id'])
# 서브세그먼트 생성
with xray_recorder.in_subsegment('validate_order'):
validate_order(order_data)
with xray_recorder.in_subsegment('save_to_database'):
save_order(order_data)
return {'status': 'success'}
def validate_order(order_data):
# 주문 유효성 검사 로직
xray_recorder.current_subsegment().put_annotation('validation_result', 'passed')
2. 성능 병목 분석
X-Ray 서비스 맵 해석
{
"service": "order-api",
"trace_id": "1-5e1b4151-2c4c8c4b6d7e8f9g0h1i2j3k",
"segments": [
{
"name": "order-processing",
"start_time": 1578675542.123,
"end_time": 1578675542.456,
"duration": 0.333,
"subsegments": [
{
"name": "DynamoDB",
"start_time": 1578675542.200,
"end_time": 1578675542.350,
"duration": 0.150
}
]
}
]
}
🌐 VPC Flow Logs 네트워크 분석
1. 네트워크 트래픽 모니터링
Flow Logs 파싱 및 분석
import pandas as pd
import boto3
def analyze_flow_logs():
# S3에서 Flow Logs 읽기
s3 = boto3.client('s3')
# Flow Logs 형식: version account-id interface-id srcaddr dstaddr srcport dstport protocol packets bytes windowstart windowend action flowlogstatus
flow_data = """
2 123456789012 eni-0123456789abcdef0 192.168.1.10 54.239.28.85 443 22 6 20 4000 1578675542 1578675572 ACCEPT OK
2 123456789012 eni-0123456789abcdef0 192.168.1.10 203.0.113.12 80 3389 6 10 2000 1578675542 1578675572 REJECT OK
"""
# 의심스러운 트래픽 패턴 감지
suspicious_patterns = {
'port_scanning': detect_port_scanning(flow_data),
'ddos_attack': detect_ddos_patterns(flow_data),
'data_exfiltration': detect_data_exfiltration(flow_data)
}
return suspicious_patterns
def detect_port_scanning(flow_data):
# 포트 스캔 패턴 감지 로직
pass
def detect_ddos_patterns(flow_data):
# DDoS 공격 패턴 감지 로직
pass
2. 자동화된 보안 대응
CloudWatch Insights 쿼리
-- 가장 많은 트래픽을 생성하는 소스 IP 분석
fields @timestamp, srcaddr, dstaddr, srcport, dstport, protocol, bytes
| filter action = "ACCEPT"
| stats sum(bytes) as total_bytes by srcaddr
| sort total_bytes desc
| limit 10
-- 차단된 트래픽 분석
fields @timestamp, srcaddr, dstaddr, srcport, dstport, protocol
| filter action = "REJECT"
| stats count() as blocked_attempts by srcaddr, dstport
| sort blocked_attempts desc
| limit 20
🚀 실전 문제 해결
문제 1: 성능 모니터링 최적화
문제 상황: 3-tier 웹 애플리케이션에서 응답 시간이 급격히 증가하고 있습니다. 다음 중 가장 효과적인 모니터링 전략은?
A) CloudWatch 기본 메트릭만 사용 B) X-Ray + CloudWatch Insights + RDS Performance Insights C) CloudTrail + VPC Flow Logs만 사용 D) Lambda 함수로 직접 모니터링 구현
정답: B
해설:
- X-Ray: 애플리케이션 레벨 분산 추적
- CloudWatch Insights: 로그 데이터 분석
- RDS Performance Insights: 데이터베이스 성능 상세 분석
문제 2: 보안 감사 설정
문제 상황: 금융 서비스에서 모든 API 호출을 추적하고 실시간 알림이 필요합니다. 최적의 구성은?
A) CloudTrail + CloudWatch Events + Lambda + SNS B) VPC Flow Logs + S3 + Athena C) X-Ray + CloudWatch Alarms D) AWS Config + CloudFormation
정답: A
해설: 실시간 보안 이벤트 감지와 알림을 위해서는 CloudTrail의 이벤트를 CloudWatch Events로 실시간 처리하고, Lambda로 분석 후 SNS를 통해 알림을 보내는 것이 가장 효과적입니다.
📈 고급 모니터링 패턴
1. 복합 메트릭 생성
수학적 표현식을 사용한 SLI 계산
# SLI (Service Level Indicator) 계산
def calculate_sli_metrics():
cloudwatch = boto3.client('cloudwatch')
# 가용성 = (총 요청 - 에러) / 총 요청 * 100
availability_expression = "(m1 - m2) / m1 * 100"
# 지연 시간 P99 계산
latency_p99 = cloudwatch.get_metric_statistics(
Namespace='AWS/ApplicationELB',
MetricName='TargetResponseTime',
Dimensions=[
{
'Name': 'LoadBalancer',
'Value': 'app/my-load-balancer/50dc6c495c0c9188'
}
],
StartTime=datetime.utcnow() - timedelta(hours=1),
EndTime=datetime.utcnow(),
Period=300,
Statistics=['Average'],
Unit='Seconds'
)
return {
'availability': availability_expression,
'latency_p99': latency_p99
}
2. 멀티 계정 모니터링
Cross-Account 모니터링 설정
# CloudFormation - 중앙 모니터링 계정
Resources:
CrossAccountRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${MonitoringAccount}:root'
Action: 'sts:AssumeRole'
Policies:
- PolicyName: CloudWatchReadOnlyAccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'cloudwatch:GetMetricStatistics'
- 'cloudwatch:ListMetrics'
- 'logs:DescribeLogGroups'
- 'logs:DescribeLogStreams'
Resource: '*'
🔧 모니터링 자동화
1. Infrastructure as Code
Terraform을 이용한 모니터링 스택 구성
# main.tf
resource "aws_cloudwatch_dashboard" "main" {
dashboard_name = "ApplicationMonitoring"
dashboard_body = jsonencode({
widgets = [
{
type = "metric"
x = 0
y = 0
width = 12
height = 6
properties = {
metrics = [
["AWS/ApplicationELB", "TargetResponseTime", "LoadBalancer", var.load_balancer_name],
["AWS/ApplicationELB", "HTTPCode_Target_2XX_Count", "LoadBalancer", var.load_balancer_name],
["AWS/ApplicationELB", "HTTPCode_Target_5XX_Count", "LoadBalancer", var.load_balancer_name]
]
period = 300
stat = "Average"
region = var.aws_region
title = "Application Performance"
}
}
]
})
}
resource "aws_cloudwatch_metric_alarm" "high_response_time" {
alarm_name = "high-response-time"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "2"
metric_name = "TargetResponseTime"
namespace = "AWS/ApplicationELB"
period = "300"
statistic = "Average"
threshold = "1"
alarm_description = "This metric monitors application response time"
alarm_actions = [aws_sns_topic.alerts.arn]
dimensions = {
LoadBalancer = var.load_balancer_name
}
}
2. 자동 해결 시스템
AWS Systems Manager를 이용한 자동 복구
import boto3
import json
def auto_remediation_handler(event, context):
# CloudWatch 알람에서 트리거된 자동 복구
alarm_name = event['AlarmName']
remediation_actions = {
'high-cpu-alarm': restart_instance,
'high-memory-alarm': scale_out,
'database-connection-alarm': restart_rds
}
if alarm_name in remediation_actions:
remediation_actions[alarm_name](event)
return {
'statusCode': 200,
'body': json.dumps('Remediation completed')
}
def restart_instance(event):
ec2 = boto3.client('ec2')
instance_id = extract_instance_id(event)
ec2.reboot_instances(InstanceIds=[instance_id])
# 알림 발송
send_notification(f"Instance {instance_id} has been restarted")
def scale_out(event):
autoscaling = boto3.client('autoscaling')
autoscaling.set_desired_capacity(
AutoScalingGroupName='my-asg',
DesiredCapacity=5,
HonorCooldown=True
)
💡 베스트 프랙티스
1. 효율적인 로그 관리
로그 라이프사이클 관리
- CloudWatch Logs: 30일 보관
- S3 Standard: 90일 보관
- S3 IA: 1년 보관
- S3 Glacier: 7년 보관
2. 비용 최적화
모니터링 비용 절감 전략
- 불필요한 메트릭 제거
- 로그 필터링 활용
- 커스텀 메트릭 최적화
- 대시보드 공유 및 재사용
3. 알람 피로도 방지
스마트 알람 설정
- 중요도별 알람 분류
- 에스컬레이션 정책 구현
- 알람 억제 규칙 설정
🎯 시험 출제 포인트
핵심 암기 사항
- CloudWatch 메트릭 보관 기간: 15개월
- CloudTrail 기본 보관 기간: 90일
- X-Ray 추적 데이터 보관: 30일
- VPC Flow Logs 대상: VPC, 서브넷, ENI
- CloudWatch Logs 실시간 처리: Kinesis Data Streams
자주 출제되는 시나리오
- 성능 모니터링: X-Ray + CloudWatch
- 보안 감사: CloudTrail + CloudWatch Events
- 네트워크 분석: VPC Flow Logs + CloudWatch Insights
- 비용 모니터링: AWS Cost Explorer + CloudWatch
- 멀티 리전 모니터링: CloudWatch Cross-Region
🚀 실습 과제
과제 1: 3-tier 애플리케이션 모니터링 구축
- CloudWatch 대시보드 생성
- X-Ray 분산 추적 설정
- 알람 및 자동 복구 구현
과제 2: 보안 모니터링 시스템 구축
- CloudTrail 설정
- 실시간 보안 이벤트 감지
- 자동 알림 시스템 구현
과제 3: 성능 최적화 모니터링
- 커스텀 메트릭 생성
- 성능 벤치마크 설정
- 자동 스케일링 연동
📚 참고 자료
모니터링과 옵저버빌리티는 AWS 아키텍처의 핵심 요소입니다. 이 가이드를 통해 실제 프로덕션 환경에서 사용할 수 있는 강력한 모니터링 시스템을 구축하는 방법을 학습하셨기를 바랍니다. 다음 포스트에서는 AWS 보안 심화 주제를 다뤄보겠습니다.
다음 포스트 예고: AWS SAA 보안 심화 - IAM 고급 정책 설계와 제로 트러스트 아키텍처 🔐