CloudWatch for ML Observability: Monitoring AI Systems at Scale
Audit trails tell you what happened. Observability tells you what is happening right now. CloudTrail captures every API call for the audit record, but it does not tell you that your SageMaker endpoint latency spiked to 8 seconds, that your Bedrock invocations are being throttled, or that your model's GPU utilization hit 98% and predictions are queuing. For that, you need Amazon CloudWatch.
CloudWatch is AWS's native observability service. For ML workloads, it provides metrics, logs, alarms, dashboards, and anomaly detection across SageMaker, Bedrock, and every supporting service in your ML infrastructure. Compliance frameworks require monitoring -- SOC 2 CC7.1 requires system monitoring, NIST 800-53 SI-4 requires information system monitoring, and ISO 27001 A.8.16 requires monitoring activities. CloudWatch is how you satisfy those requirements for AI systems.
This guide covers CloudWatch metrics for SageMaker and Bedrock, custom metrics for model quality, dashboard creation, alarm configuration, anomaly detection, and X-Ray tracing for ML pipelines.
CloudWatch Metrics for SageMaker Endpoints
SageMaker automatically publishes metrics to CloudWatch for every deployed endpoint. These metrics are your real-time window into model health and performance.
Key SageMaker Endpoint Metrics
| Metric | Namespace | What It Tells You | Compliance Relevance |
|---|---|---|---|
Invocations |
AWS/SageMaker |
Total inference requests per period | Capacity planning, usage auditing |
ModelLatency |
AWS/SageMaker |
Time the model takes to respond (microseconds) | SLA compliance, performance monitoring |
OverheadLatency |
AWS/SageMaker |
Time for SageMaker infrastructure overhead | Infrastructure health |
Invocation4XXErrors |
AWS/SageMaker |
Client-side errors (bad requests) | Integration health, input validation |
Invocation5XXErrors |
AWS/SageMaker |
Server-side errors (model failures) | Availability monitoring, incident detection |
InvocationsPerInstance |
AWS/SageMaker |
Requests per instance for auto-scaling decisions | Capacity governance |
CPUUtilization |
/aws/sagemaker/Endpoints |
CPU usage per instance | Resource efficiency, right-sizing |
MemoryUtilization |
/aws/sagemaker/Endpoints |
Memory usage per instance | OOM risk detection |
GPUUtilization |
/aws/sagemaker/Endpoints |
GPU usage per instance (GPU instances only) | GPU resource governance |
GPUMemoryUtilization |
/aws/sagemaker/Endpoints |
GPU memory usage per instance | GPU memory pressure detection |
DiskUtilization |
/aws/sagemaker/Endpoints |
Disk usage per instance | Storage pressure detection |
The distinction between ModelLatency and OverheadLatency matters for troubleshooting. If total latency spikes but ModelLatency is stable, the problem is infrastructure. If ModelLatency spikes, the model itself is struggling.
CloudWatch Metrics for Amazon Bedrock
Bedrock publishes its own set of CloudWatch metrics. Since Bedrock manages the infrastructure, the metrics focus on invocations, latency, tokens, and throttling rather than CPU/GPU utilization.
Key Bedrock Metrics
| Metric | Namespace | What It Tells You | Compliance Relevance |
|---|---|---|---|
InvocationCount |
AWS/Bedrock |
Total model invocations per period | Usage auditing, cost governance |
InvocationLatency |
AWS/Bedrock |
End-to-end response time (milliseconds) | SLA compliance, UX monitoring |
InvocationClientErrors |
AWS/Bedrock |
Client-side errors (4xx) | Integration health |
InvocationServerErrors |
AWS/Bedrock |
Server-side errors (5xx) | Availability monitoring |
ThrottleCount |
AWS/Bedrock |
Requests rejected due to rate limiting | Capacity governance |
InputTokenCount |
AWS/Bedrock |
Total input tokens processed | Cost governance, usage auditing |
OutputTokenCount |
AWS/Bedrock |
Total output tokens generated | Cost governance, usage auditing |
InvocationThrottles |
AWS/Bedrock |
Rate-limited invocation count | Capacity planning |
Token count metrics are critical for cost governance. A misconfigured application sending unnecessarily long prompts can generate massive costs. Monitoring InputTokenCount and OutputTokenCount by model ID catches anomalies before they become billing surprises.
Compliance Tip: Bedrock metrics are dimensioned by
ModelId. Always filter by model ID in your alarms and dashboards. Granular monitoring by model ID satisfies SOC 2 CC7.1's requirement for monitoring that detects anomalies relevant to specific systems.
Custom Metrics for Model Quality
CloudWatch's built-in SageMaker and Bedrock metrics cover infrastructure health. They do not cover model quality -- whether your model's predictions are actually correct. For that, you need custom metrics.
import boto3
import time
from datetime import datetime
cloudwatch = boto3.client("cloudwatch")
def publish_model_quality_metrics(
model_name: str,
accuracy: float,
precision: float,
recall: float,
f1_score: float,
false_positive_rate: float,
prediction_count: int,
):
"""Publish model quality metrics to CloudWatch for compliance monitoring."""
timestamp = datetime.utcnow()
cloudwatch.put_metric_data(
Namespace="MLGovernance/ModelQuality",
MetricData=[
{
"MetricName": "Accuracy",
"Dimensions": [{"Name": "ModelName", "Value": model_name}],
"Timestamp": timestamp,
"Value": accuracy,
"Unit": "None",
"StorageResolution": 60,
},
{
"MetricName": "Precision",
"Dimensions": [{"Name": "ModelName", "Value": model_name}],
"Timestamp": timestamp,
"Value": precision,
"Unit": "None",
"StorageResolution": 60,
},
{
"MetricName": "Recall",
"Dimensions": [{"Name": "ModelName", "Value": model_name}],
"Timestamp": timestamp,
"Value": recall,
"Unit": "None",
"StorageResolution": 60,
},
{
"MetricName": "F1Score",
"Dimensions": [{"Name": "ModelName", "Value": model_name}],
"Timestamp": timestamp,
"Value": f1_score,
"Unit": "None",
"StorageResolution": 60,
},
{
"MetricName": "FalsePositiveRate",
"Dimensions": [{"Name": "ModelName", "Value": model_name}],
"Timestamp": timestamp,
"Value": false_positive_rate,
"Unit": "None",
"StorageResolution": 60,
},
{
"MetricName": "PredictionCount",
"Dimensions": [{"Name": "ModelName", "Value": model_name}],
"Timestamp": timestamp,
"Value": prediction_count,
"Unit": "Count",
"StorageResolution": 60,
},
],
)
# Example: publish metrics after a batch evaluation job
publish_model_quality_metrics(
model_name="churn-predictor-v3",
accuracy=0.94,
precision=0.87,
recall=0.83,
f1_score=0.85,
false_positive_rate=0.06,
prediction_count=15420,
)
The StorageResolution of 60 seconds enables high-resolution metrics. For compliance, 60-second resolution means you can demonstrate that your model quality was continuously monitored, not just checked once a day. This satisfies the "continuous" requirement in NIST 800-53 SI-4 (information system monitoring).
Building an ML Observability Dashboard
A CloudWatch dashboard consolidates metrics from SageMaker, Bedrock, and your custom model quality namespace into a single view. For compliance, dashboards serve as evidence that you have operational monitoring in place.
aws cloudwatch put-dashboard \
--dashboard-name "ML-Governance-Overview" \
--dashboard-body '{
"widgets": [
{
"type": "metric",
"x": 0, "y": 0, "width": 12, "height": 6,
"properties": {
"title": "SageMaker Endpoint Latency (p50/p90/p99)",
"metrics": [
["AWS/SageMaker", "ModelLatency", "EndpointName", "churn-predictor-v3-endpoint", {"stat": "p50", "label": "p50 Latency"}],
["...", {"stat": "p90", "label": "p90 Latency"}],
["...", {"stat": "p99", "label": "p99 Latency"}]
],
"period": 300,
"region": "us-east-1",
"view": "timeSeries"
}
},
{
"type": "metric",
"x": 12, "y": 0, "width": 12, "height": 6,
"properties": {
"title": "SageMaker Endpoint Errors",
"metrics": [
["AWS/SageMaker", "Invocation4XXErrors", "EndpointName", "churn-predictor-v3-endpoint", {"stat": "Sum", "label": "4XX Errors", "color": "#ff9900"}],
["AWS/SageMaker", "Invocation5XXErrors", "EndpointName", "churn-predictor-v3-endpoint", {"stat": "Sum", "label": "5XX Errors", "color": "#d13212"}]
],
"period": 300,
"region": "us-east-1",
"view": "timeSeries"
}
},
{
"type": "metric",
"x": 0, "y": 6, "width": 12, "height": 6,
"properties": {
"title": "Bedrock Invocations and Throttles",
"metrics": [
["AWS/Bedrock", "InvocationCount", "ModelId", "anthropic.claude-3-sonnet-20240229-v1:0", {"stat": "Sum", "label": "Invocations"}],
["AWS/Bedrock", "ThrottleCount", "ModelId", "anthropic.claude-3-sonnet-20240229-v1:0", {"stat": "Sum", "label": "Throttles", "color": "#d13212"}]
],
"period": 300,
"region": "us-east-1",
"view": "timeSeries"
}
},
{
"type": "metric",
"x": 12, "y": 6, "width": 12, "height": 6,
"properties": {
"title": "Bedrock Token Usage",
"metrics": [
["AWS/Bedrock", "InputTokenCount", "ModelId", "anthropic.claude-3-sonnet-20240229-v1:0", {"stat": "Sum", "label": "Input Tokens"}],
["AWS/Bedrock", "OutputTokenCount", "ModelId", "anthropic.claude-3-sonnet-20240229-v1:0", {"stat": "Sum", "label": "Output Tokens"}]
],
"period": 300,
"region": "us-east-1",
"view": "timeSeries"
}
},
{
"type": "metric",
"x": 0, "y": 12, "width": 12, "height": 6,
"properties": {
"title": "Model Quality - Accuracy and F1 Score",
"metrics": [
["MLGovernance/ModelQuality", "Accuracy", "ModelName", "churn-predictor-v3", {"stat": "Average", "label": "Accuracy"}],
["MLGovernance/ModelQuality", "F1Score", "ModelName", "churn-predictor-v3", {"stat": "Average", "label": "F1 Score"}]
],
"period": 86400,
"region": "us-east-1",
"view": "timeSeries",
"annotations": {
"horizontal": [
{"label": "Minimum Accuracy Threshold", "value": 0.85, "color": "#d13212"}
]
}
}
},
{
"type": "metric",
"x": 12, "y": 12, "width": 12, "height": 6,
"properties": {
"title": "SageMaker GPU/CPU Utilization",
"metrics": [
["/aws/sagemaker/Endpoints", "CPUUtilization", "EndpointName", "churn-predictor-v3-endpoint", {"stat": "Average", "label": "CPU %"}],
["/aws/sagemaker/Endpoints", "MemoryUtilization", "EndpointName", "churn-predictor-v3-endpoint", {"stat": "Average", "label": "Memory %"}]
],
"period": 300,
"region": "us-east-1",
"view": "timeSeries"
}
}
]
}'
This dashboard provides six panels covering endpoint latency, errors, Bedrock usage and throttling, token consumption, model quality trends, and resource utilization. Take a monthly screenshot of this dashboard and include it in your compliance evidence package -- auditors respond well to visual evidence of operational monitoring.
Alarms and Anomaly Detection
Dashboards are passive. Alarms are active. For compliance, you need both. CloudWatch alarms trigger when metrics cross defined thresholds, and anomaly detection alarms trigger when metrics deviate from learned patterns.
Static Threshold Alarms
import boto3
cloudwatch = boto3.client("cloudwatch")
# Alarm: SageMaker endpoint 5XX error rate exceeds 1%
cloudwatch.put_metric_alarm(
AlarmName="churn-v3-endpoint-5xx-rate",
AlarmDescription="SageMaker endpoint server error rate exceeds 1%",
Namespace="AWS/SageMaker",
MetricName="Invocation5XXErrors",
Dimensions=[
{"Name": "EndpointName", "Value": "churn-predictor-v3-endpoint"},
],
Statistic="Sum",
Period=300,
EvaluationPeriods=3,
DatapointsToAlarm=2,
Threshold=10,
ComparisonOperator="GreaterThanThreshold",
AlarmActions=[
"arn:aws:sns:us-east-1:123456789:ml-ops-alerts",
"arn:aws:sns:us-east-1:123456789:ml-governance-alerts",
],
OKActions=[
"arn:aws:sns:us-east-1:123456789:ml-ops-alerts",
],
TreatMissingData="notBreaching",
Tags=[
{"Key": "compliance", "Value": "soc2-cc7.1"},
{"Key": "severity", "Value": "high"},
],
)
# Alarm: Model quality accuracy drops below threshold
cloudwatch.put_metric_alarm(
AlarmName="churn-v3-accuracy-degradation",
AlarmDescription="Model accuracy dropped below 85% minimum threshold",
Namespace="MLGovernance/ModelQuality",
MetricName="Accuracy",
Dimensions=[
{"Name": "ModelName", "Value": "churn-predictor-v3"},
],
Statistic="Average",
Period=86400,
EvaluationPeriods=1,
Threshold=0.85,
ComparisonOperator="LessThanThreshold",
AlarmActions=[
"arn:aws:sns:us-east-1:123456789:ml-governance-alerts",
],
TreatMissingData="breaching",
Tags=[
{"Key": "compliance", "Value": "nist-si-4,iso27001-a.8.16"},
{"Key": "severity", "Value": "critical"},
],
)
# Alarm: Bedrock throttle rate indicates capacity issues
cloudwatch.put_metric_alarm(
AlarmName="bedrock-claude-throttle-rate",
AlarmDescription="Bedrock throttle count exceeds acceptable threshold",
Namespace="AWS/Bedrock",
MetricName="ThrottleCount",
Dimensions=[
{"Name": "ModelId", "Value": "anthropic.claude-3-sonnet-20240229-v1:0"},
],
Statistic="Sum",
Period=300,
EvaluationPeriods=2,
DatapointsToAlarm=2,
Threshold=50,
ComparisonOperator="GreaterThanThreshold",
AlarmActions=[
"arn:aws:sns:us-east-1:123456789:ml-ops-alerts",
],
TreatMissingData="notBreaching",
Tags=[
{"Key": "compliance", "Value": "soc2-cc7.1"},
{"Key": "severity", "Value": "medium"},
],
)
Notice the dual SNS topic pattern: ml-ops-alerts goes to the engineering on-call rotation, and ml-governance-alerts goes to the compliance team. Operations fixes the problem, governance documents it.
Anomaly Detection Alarms
Static thresholds work for known failure modes. Anomaly detection catches unknown unknowns -- patterns you did not anticipate.
# Create an anomaly detection model for endpoint latency
cloudwatch.put_anomaly_detector(
Namespace="AWS/SageMaker",
MetricName="ModelLatency",
Dimensions=[
{"Name": "EndpointName", "Value": "churn-predictor-v3-endpoint"},
],
Stat="p99",
Configuration={
"ExcludedTimeRanges": [],
"MetricTimezone": "UTC",
},
)
# Alarm based on anomaly detection band
cloudwatch.put_metric_alarm(
AlarmName="churn-v3-latency-anomaly",
AlarmDescription="Model latency is anomalous based on learned patterns",
Metrics=[
{
"Id": "m1",
"MetricStat": {
"Metric": {
"Namespace": "AWS/SageMaker",
"MetricName": "ModelLatency",
"Dimensions": [
{"Name": "EndpointName", "Value": "churn-predictor-v3-endpoint"},
],
},
"Period": 300,
"Stat": "p99",
},
"ReturnData": True,
},
{
"Id": "ad1",
"Expression": "ANOMALY_DETECTION_BAND(m1, 3)",
"Label": "Latency Anomaly Band",
"ReturnData": True,
},
],
ComparisonOperator="GreaterThanUpperThreshold",
ThresholdMetricId="ad1",
EvaluationPeriods=3,
DatapointsToAlarm=2,
AlarmActions=[
"arn:aws:sns:us-east-1:123456789:ml-ops-alerts",
],
TreatMissingData="notBreaching",
Tags=[
{"Key": "compliance", "Value": "nist-si-4"},
{"Key": "detection-type", "Value": "anomaly"},
],
)
The ANOMALY_DETECTION_BAND(m1, 3) expression creates a band 3 standard deviations from the learned pattern. CloudWatch uses up to 14 days of historical data to learn normal patterns, including daily and weekly seasonality.
X-Ray Tracing for ML Pipelines
CloudWatch metrics tell you what is slow. X-Ray tells you why. For complex ML pipelines that span multiple services -- Lambda preprocessing, SageMaker inference, DynamoDB feature lookup, S3 artifact retrieval -- X-Ray provides distributed tracing that reveals exactly where time is spent.
import boto3
from aws_xray_sdk.core import xray_recorder, patch_all
# Patch boto3 and other libraries for automatic X-Ray instrumentation
patch_all()
# Configure X-Ray with ML-specific annotations
xray_recorder.configure(
sampling=True,
context_missing="LOG_ERROR",
plugins=("EC2Plugin", "ECSPlugin"),
daemon_address="127.0.0.1:2000",
)
@xray_recorder.capture("ml_inference_pipeline")
def run_inference(input_data: dict) -> dict:
"""Full inference pipeline with X-Ray tracing."""
# Add compliance-relevant annotations
segment = xray_recorder.current_segment()
segment.put_annotation("model_name", "churn-predictor-v3")
segment.put_annotation("model_version", "3.1")
segment.put_annotation("compliance_framework", "soc2-cc7.1")
# Subsegment: Feature engineering
with xray_recorder.in_subsegment("feature_engineering") as subsegment:
subsegment.put_metadata("input_features", list(input_data.keys()))
features = preprocess_features(input_data)
# Subsegment: Model invocation
with xray_recorder.in_subsegment("sagemaker_invocation") as subsegment:
sagemaker_runtime = boto3.client("sagemaker-runtime")
response = sagemaker_runtime.invoke_endpoint(
EndpointName="churn-predictor-v3-endpoint",
ContentType="application/json",
Body=json.dumps(features),
)
prediction = json.loads(response["Body"].read())
subsegment.put_annotation("prediction_value", prediction["score"])
# Subsegment: Post-processing and audit logging
with xray_recorder.in_subsegment("post_processing") as subsegment:
result = format_response(prediction)
log_prediction_audit(input_data, result)
subsegment.put_annotation("result_class", result["class"])
return result
X-Ray traces feed into the CloudWatch ServiceMap, providing a visual topology of your ML pipeline. For compliance, this serves as living architecture documentation -- evidence for NIST 800-53 SI-4 and SOC 2 CC7.1.
Compliance Mapping Table
The following table maps CloudWatch ML observability capabilities to specific compliance framework requirements.
| CloudWatch Capability | SOC 2 | NIST 800-53 | ISO 27001 | Evidence Artifact |
|---|---|---|---|---|
| SageMaker endpoint metrics | CC7.1 (system monitoring) | SI-4 (system monitoring) | A.8.16 (monitoring activities) | Metric graphs, dashboard exports |
| Bedrock invocation metrics | CC7.1 (system monitoring) | SI-4 (system monitoring) | A.8.16 (monitoring activities) | Metric graphs, dashboard exports |
| Custom model quality metrics | CC7.1 (system monitoring) | SI-4 (system monitoring) | A.8.16 (monitoring activities) | Custom metric data, trend reports |
| ML observability dashboards | CC7.1 (system monitoring) | SI-4 (system monitoring) | A.8.16 (monitoring activities) | Dashboard screenshots, configuration JSON |
| Static threshold alarms | CC7.1 (monitoring), CC7.2 (incident response) | SI-4 (monitoring), IR-4 (incident handling) | A.8.16 (monitoring), A.5.24 (incident mgmt) | Alarm configuration, alarm history |
| Anomaly detection alarms | CC7.1 (monitoring) | SI-4 (monitoring) | A.8.16 (monitoring activities) | Anomaly detector config, alarm history |
| X-Ray distributed tracing | CC7.1 (system monitoring) | SI-4 (system monitoring) | A.8.16 (monitoring activities) | Service map, trace data |
| CloudWatch Logs (ML pipeline logs) | CC7.1 (monitoring) | AU-6 (audit review) | A.8.15 (logging) | Log group data, log insights queries |
Key Takeaway: CloudWatch is the real-time complement to CloudTrail's historical audit record. CloudWatch tells you what is happening now; CloudTrail tells you what happened in the past. Both are required for comprehensive ML compliance.
How Claw GRC Integrates CloudWatch Alerting Data
CloudWatch generates metrics, alarms, and traces. Claw GRC transforms that operational data into compliance intelligence.
Alarm-to-control mapping. Claw GRC maps every CloudWatch alarm to the compliance controls it monitors. When the churn-v3-endpoint-5xx-rate alarm fires, Claw GRC automatically creates findings against SOC 2 CC7.1 and NIST 800-53 SI-4. No manual mapping required.
Alarm coverage analysis. Claw GRC audits your CloudWatch alarm configuration against your compliance requirements. If SOC 2 CC7.1 requires monitoring of all production systems but your Bedrock model has no alarms configured, Claw GRC flags the gap. Coverage analysis runs continuously -- not just at audit time.
Metric trend analysis. Claw GRC ingests CloudWatch metric data and produces compliance-oriented reports: percentage of time within SLA, threshold breaches per month, and mean time to resolution. These are the metrics auditors care about.
Incident correlation. When multiple alarms fire in a short window, Claw GRC correlates them into a single incident. This produces cleaner compliance evidence and more accurate incident counts for SOC 2 CC7.2.
Dashboard evidence automation. Claw GRC captures CloudWatch dashboard snapshots on a configurable schedule and stores them as compliance evidence. Combined with CloudTrail audit trails and AWS Cloud Security controls, you have a complete evidence package for ML observability compliance.
Next Steps
ML observability is one pillar of a comprehensive AI governance program. To build out the full picture:
- Complete Guide to AWS AI/ML Governance -- the hub article covering all 10 governance pillars
- AWS Cloud Security for AI Compliance -- IAM, SCPs, and network controls for AI workloads
- CloudTrail for ML Audit Trails -- the historical audit record that complements real-time observability
Each guide includes hands-on code examples, compliance mapping tables, and evidence collection strategies you can implement today.
Start your ML observability compliance assessment with Claw GRC →