AWS Cloud Architecture•Part 5: Security, IAM, Messaging & Enterprise Deployments (51 - 65)
CloudWatch vs CloudTrail.
In Simple Words:
- CloudWatch: Operational monitoring, metrics (CPU, memory, latency), log aggregation, and alarm dashboards.
- CloudTrail: Audit trail recording who did what, when, and from where across all AWS API calls and console actions.
hcl
# CloudWatch Alarm triggering SNS alert if 5XX errors exceed threshold:
resource "aws_cloudwatch_metric_alarm" "api_5xx" {
alarm_name = "high-5xx-error-rate"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 2
metric_name = "HTTPCode_Target_5XX_Count"
namespace = "AWS/ApplicationELB"
period = 60
statistic = "Sum"
threshold = 10
alarm_actions = [aws_sns_topic.alerts.arn]
}