Based on the MLA-C01 exam guideReport an error
To diagnose latency, first draw where a request travels. CloudWatch metrics correspond to each segment of this path.
[Client]
│ ① Network · front end (API Gateway / Lambda) ← not visible in CloudWatch → X-Ray
▼
┌───────────────────────────────────────────┐
│ SageMaker endpoint │
│ ┌─────────────────┐ ┌───────────────────┐ │
│ │ Request receipt·routing │ ──▶ │ Model container inference │ │
│ └─────────────────┘ └───────────────────┘ │
│ ② OverheadLatency ③ ModelLatency │
│ Resource state: CPUUtilization / MemoryUtilization / GPUUtilization
│ Invocation results: Invocations / Invocation4XXErrors / Invocation5XXErrors
└───────────────────────────────────────────┘
│
▼ CloudWatch Metrics ──▶ Alarm ──▶ SNS · Application Auto Scaling · Lambda
CloudWatch Logs ──▶ Logs Insights (cause details)SageMaker automatically sends endpoint invocation and instance state to CloudWatch. These are the metrics the exam covers.
| Metric | Meaning | Where (namespace) |
|---|---|---|
ModelLatency | Time the model took to run inference (microseconds) | AWS/SageMaker |
OverheadLatency | SageMaker overhead (additional request-handling time) | AWS/SageMaker |
Invocations | Number of endpoint invocations | AWS/SageMaker |
Invocation4XXErrors / 5XXErrors | Number of client/server error invocations | AWS/SageMaker |
CPUUtilization / MemoryUtilization / GPUUtilization | Instance resource utilization | /aws/sagemaker/Endpoints |
Total response latency is roughly ModelLatency + OverheadLatency. When latency suddenly rises, you have to split it into whether it is ModelLatency (a model or instance load problem) or OverheadLatency (a request-handling or payload problem) to pin down the cause.
Even for the same metric, what you suspect and what you touch first differs when it spikes.
| Metric | Meaning when it spikes | First action |
|---|---|---|
ModelLatency | Model computation is taking long - load, model size, batch settings | Upgrade instance type, add instances, slim down the model |
OverheadLatency | Request-handling overhead - large payloads, serialization, model loading | Shrink or compress the payload, simplify the request format |
Invocation4XXErrors | The caller's fault - format, authentication, size exceeded | Validate the client payload, check the input schema |
Invocation5XXErrors | Server-side problem - container crash, timeout, resource shortage | Check container logs, add instances, raise the timeout |
CPUUtilization | Compute saturation (multi-core, so values over 100% can be reported) | Add instances or change type |
MemoryUtilization | Memory pressure - tends to show up together with 5XX due to OOM | Switch to a larger-memory type, reduce batch size |
Invocations | The traffic change itself | Reset the Auto Scaling target, capacity planning |
💡 Related theory: 4XX and 5XX errors differ in who is responsible. 4XX (client errors) come from the caller's wrong input, wrong format, or authentication problems, and are solved by payload validation or fixing the client. 5XX (server errors) are server-side problems such as model container crashes, timeouts, or resource shortage. If 5XX surges, you need to add instances, check health, and debug the container. When the exam asks "to narrow down the cause of an error-rate surge", the 4XX/5XX split is the first step.
Just looking at metrics is meaningless. When a threshold is crossed, you must notify or act automatically. A CloudWatch Alarm changes its state to ALARM when a metric meets the condition and triggers an SNS notification, Auto Scaling, a Lambda trigger, and so on.
import boto3
cw = boto3.client("cloudwatch")
cw.put_metric_alarm(
AlarmName="HighModelLatency",
Namespace="AWS/SageMaker",
MetricName="ModelLatency",
Dimensions=[{"Name": "EndpointName", "Value": "my-endpoint"},
{"Name": "VariantName", "Value": "AllTraffic"}],
Statistic="Average",
Period=60, # evaluate in 60-second units
EvaluationPeriods=3, # ALARM after 3 consecutive breaches
Threshold=200000, # 200,000 microseconds = 200ms
ComparisonOperator="GreaterThanThreshold",
AlarmActions=["arn:aws:sns:us-east-1:123456789012:ops-alerts"],
TreatMissingData="notBreaching", # do not treat missing data (zero traffic) as a breach
)The key parameters are Period (evaluation interval), EvaluationPeriods (how many consecutive breaches before ALARM), Threshold, and ComparisonOperator. Increasing EvaluationPeriods reduces false positives from momentary spikes.
| Alarm parameter | What it adjusts | If set wrong |
|---|---|---|
Period | How many seconds the metric is bundled for evaluation | Too short is noise, too long delays detection |
EvaluationPeriods | How many consecutive periods must breach for ALARM | At 1, every spike is a false positive |
Statistic | Average / Sum / Maximum / p99, etc. | Looking only at the average for latency misses tail latency |
TreatMissingData | Interpretation of intervals with no data | False alarms can fire at night when traffic is zero |
AlarmActions | What to do when it fires | If you only attach a notification, it is neglected until a person wakes up |
For latency, the tail (p90, p99) is closer to what users feel than the average. If the average is 80ms but p99 is 3 seconds, 1 in 100 people effectively experiences a failure. Setting a single average alarm and concluding "latency is normal" is the most common illusion in operations.
⚠️ Trap: When latency rises due to a traffic surge, the standard is not "send an alarm and stop" but Auto Scaling to add instances automatically. SageMaker endpoint Auto Scaling usually attaches a policy targeting a metric such as
SageMakerVariantInvocationsPerInstance(invocations per instance). On the exam, "automatically respond to traffic swings" should make you think of an Application Auto Scaling policy, not a simple alarm.
aas = boto3.client("application-autoscaling")
# ① Register the scalable target - adjust the variant's instance count between 1 and 8
aas.register_scalable_target(
ServiceNamespace="sagemaker",
ResourceId="endpoint/my-endpoint/variant/AllTraffic",
ScalableDimension="sagemaker:variant:DesiredInstanceCount",
MinCapacity=1, MaxCapacity=8,
)
# ② Target tracking policy - keep invocations per instance near the target value
aas.put_scaling_policy(
PolicyName="invocations-target-tracking",
ServiceNamespace="sagemaker",
ResourceId="endpoint/my-endpoint/variant/AllTraffic",
ScalableDimension="sagemaker:variant:DesiredInstanceCount",
PolicyType="TargetTrackingScaling",
TargetTrackingScalingPolicyConfiguration={
"TargetValue": 1000.0,
"PredefinedMetricSpecification": {
"PredefinedMetricType": "SageMakerVariantInvocationsPerInstance"},
"ScaleInCooldown": 300, "ScaleOutCooldown": 60,
},
)The stdout/stderr of the endpoint container flows automatically to CloudWatch Logs. The log group is usually of the form /aws/sagemaker/Endpoints/{endpoint-name}. Model loading failures, exception stack traces, warnings during inference, and so on are seen here.
logs = boto3.client("logs")
# Filter recent errors from a specific log group
response = logs.filter_log_events(
logGroupName="/aws/sagemaker/Endpoints/my-endpoint",
filterPattern="ERROR", # only logs containing ERROR
limit=50,
)To query and aggregate large volumes of logs with SQL-like syntax, use CloudWatch Logs Insights. It is useful for analyses such as "top causes of 5xx errors in the last hour".
fields @timestamp, @message
| filter @message like /ERROR|Exception|Timeout/
| stats count() as hits by bin(5m)
| sort @timestamp desc| What do you want to know | Tool |
|---|---|
| Are latency and error rate normal right now | CloudWatch Metrics + Alarm |
| The specific exception and stack trace of that error | CloudWatch Logs |
| In which time window and pattern the errors clustered | Logs Insights aggregation query |
| Whether the slow segment is the model or the front end | X-Ray trace |
When the endpoint is entangled with other services (a preprocessing Lambda, external APIs, a database), it is hard to see at a glance which segment is causing latency. AWS X-Ray tracks the time taken in each segment the request passes through and visualizes the bottleneck. "The overall response is slow but ModelLatency is normal → the front-end Lambda or network is the bottleneck" can be confirmed with an X-Ray trace.
Operational monitoring is organized as the "three pillars of observability". Metrics (what and how much - latency, error rate, utilization), logs (what happened - event and exception details), traces (where - request flow and per-segment latency). CloudWatch Metrics, Logs, and X-Ray correspond exactly to these three pillars. The troubleshooting order usually flows "detect an anomaly with metrics → confirm cause details with logs → pinpoint which segment with traces".
Operational monitoring includes cost as well. An always-on real-time endpoint incurs cost even when idle, so if Invocations stays near 0 for a long time, consider switching to serverless or asynchronous. Gather latency, errors, utilization, and invocation volume on a CloudWatch dashboard to see the operational state at a glance.
| Symptom | Common cause | Action |
|---|---|---|
Total latency rose but ModelLatency is normal | The front end (Lambda, API Gateway, network) is the bottleneck | Pinpoint the segment with an X-Ray trace, then improve that segment |
Only ModelLatency spikes | Instance load, heavy model | Upgrade instance type or add instances, slim down the model |
Only OverheadLatency spikes | Large payload, serialization cost, frequent cold loading | Shrink request size, simplify the format |
Invocation5XXErrors surge | Container crash, OOM, inference timeout | Check container logs, larger-memory type, raise timeout and instance count |
Invocation4XXErrors surge | Wrong input format, authentication, payload size exceeded | Strengthen client validation, document the input schema |
| Latency spikes every time traffic grows | Auto Scaling not set or target value too high | Register Application Auto Scaling + lower the target value |
| False alarms keep firing at night | Missing-data handling for zero-traffic intervals | TreatMissingData="notBreaching", adjust the evaluation period |
| Average latency is normal but users complain | Tail latency (p99) is large | Add a p99-based alarm, secure instance headroom |
| Logs are not visible | The execution role lacks CloudWatch Logs write permission | Grant log permissions to the endpoint execution IAM role |
| Few invocations but costs keep accruing | A real-time endpoint is running continuously while idle | Consider switching to serverless or asynchronous inference, delete unused endpoints |
In the next post, we look at the responses that follow when monitoring detects drift or performance degradation - automated retraining pipelines and A/B and shadow testing.
SageMakerVariantInvocationsPerInstance).Click a choice to reveal the answer and explanation.
Question 1
An endpoint's responses suddenly became slow. ModelLatency is the same as usual, but only the overall response time spiked. Which of the following is the most appropriate tool for narrowing down the cause?
Question 2
Invocation5XXErrors spiked on an endpoint. What is the most likely cause area?
Question 3
In a CloudWatch Alarm, what does EvaluationPeriods=3 mean?
Question 4
Traffic surged and response latency increased. You set up a CloudWatch alarm, but the instances are still under heavy load. What action is most needed?
Question 5
When you want to view the stderr messages of an endpoint container in CloudWatch Logs, what is the log group name?