> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Monitoring and Auditing ML Systems

> Monitoring and auditing production ML systems on AWS using CloudWatch, CloudTrail, SageMaker Model Monitor, AWS Config, IAM and KMS to detect drift, ensure observability, security, and compliance

In this lesson we cover a critical post-deployment phase of MLOps: monitoring and auditing machine learning systems so they remain reliable, secure, and compliant in production.

Monitoring focuses on runtime observability—metrics, logs, and alerts—while auditing provides an immutable record of actions and configuration changes that supports accountability and compliance. In AWS, common building blocks for these capabilities are CloudWatch for telemetry and CloudTrail for API audit trails, often combined with SageMaker Model Monitor and AWS Config for model-specific monitoring and compliance checks.

<Callout icon="lightbulb" color="#1CB2FE">
  Monitoring gives you runtime visibility to detect and respond to issues quickly; auditing preserves a historical record required for investigations, governance, and compliance.
</Callout>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/GR4ncKaD2FS-haHS/images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/ml-systems-monitoring-audit-aws.jpg?fit=max&auto=format&n=GR4ncKaD2FS-haHS&q=85&s=572e3e286efd27a0d9832cb6a07fa206" alt="The image is about monitoring and auditing ML systems using AWS CloudWatch to check system health and performance, and AWS CloudTrail to record actions for accountability and compliance." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/ml-systems-monitoring-audit-aws.jpg" />
</Frame>

## Why monitor and audit ML systems?

Consider the full ML lifecycle: training pipelines, model artifacts, and inference endpoints. Continuous monitoring and auditing enable you to:

* Detect runtime issues (e.g., latency spikes, increased error rates).
* Detect data and concept drift that degrade model performance.
* Maintain a verifiable history of who did what and when for compliance, debugging, and reproducibility.
* Automate incident workflows to reduce mean time to detection and recovery.

To implement these capabilities on AWS, combine services designed for observability, model quality, and governance.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/GR4ncKaD2FS-haHS/images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/ml-monitoring-auditing-flowchart.jpg?fit=max&auto=format&n=GR4ncKaD2FS-haHS&q=85&s=4f4d4222352fc04400cc310e72476941" alt="The image is a flowchart explaining the importance of monitoring and auditing machine learning systems, highlighting tools like CloudWatch, Model Monitor, and CloudTrail to ensure reliable and compliant ML." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/ml-monitoring-auditing-flowchart.jpg" />
</Frame>

## Key AWS services and their roles

| Service                 |                                                                                                                                Role in ML monitoring & auditing | Useful links                                                                                                                             |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------------------------------- |
| AWS CloudWatch          | Collects metrics and logs from ML infrastructure and applications; supports alarms, dashboards, anomaly detection, and EventBridge integrations for automation. | [https://aws.amazon.com/cloudwatch/](https://aws.amazon.com/cloudwatch/)                                                                 |
| AWS CloudTrail          |                                           Records management- and data-plane API calls for a complete audit trail of actions and events across the AWS account. | [https://aws.amazon.com/cloudtrail/](https://aws.amazon.com/cloudtrail/)                                                                 |
| AWS Config              |                                         Continuously records resource configurations and evaluates them against rules for compliance reporting and remediation. | [https://aws.amazon.com/config/](https://aws.amazon.com/config/)                                                                         |
| SageMaker Model Monitor |                                    Captures inference data, establishes baselines, and detects distribution drift, schema violations, and model quality issues. | [https://docs.aws.amazon.com/sagemaker/latest/dg/model-monitor.html](https://docs.aws.amazon.com/sagemaker/latest/dg/model-monitor.html) |

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/GR4ncKaD2FS-haHS/images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/aws-tools-monitoring-auditing-ml-systems.jpg?fit=max&auto=format&n=GR4ncKaD2FS-haHS&q=85&s=493d32490c6cab2cd3d6916f8d6e74b9" alt="The image lists AWS tools for monitoring and auditing ML systems, including AWS CloudWatch, AWS CloudTrail, AWS Config, and SageMaker Model Monitor." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/aws-tools-monitoring-auditing-ml-systems.jpg" />
</Frame>

## Monitoring with CloudWatch (runtime telemetry)

A typical runtime monitoring flow:

1. Your ML endpoint (for example, a SageMaker endpoint) emits metrics—latency, request counts, error counts—and streams logs.
2. CloudWatch ingests those metrics and logs.
3. You define alarms (threshold or anomaly-based), dashboards, and automated responses using EventBridge and Lambda to handle incidents.

What to monitor (examples):

| Category      | Metrics to track                                              |
| ------------- | ------------------------------------------------------------- |
| Latency       | P50 / P95 / P99 latency percentiles                           |
| Errors        | Error rates, HTTP 4xx/5xx breakdown                           |
| Throughput    | Request volume, requests/sec                                  |
| Resources     | CPU, memory, GPU utilization of serving instances             |
| Model quality | Runtime-calculated quality metrics or custom inference scores |

When an alarm fires, route it to an incident playbook: create a ticket, trigger auto-scaling, block suspicious traffic, or route captured data to a drift analysis pipeline.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/GR4ncKaD2FS-haHS/images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/ml-monitoring-cloudwatch-sagemaker-flow.jpg?fit=max&auto=format&n=GR4ncKaD2FS-haHS&q=85&s=3c273d0bb9d1674f1296098b8a6ba6e2" alt="The image illustrates the process of monitoring machine learning systems with CloudWatch, showing the flow from an ML endpoint via SageMaker to CloudWatch, which then tracks metrics and alarms for latency and errors." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/ml-monitoring-cloudwatch-sagemaker-flow.jpg" />
</Frame>

## Detecting data drift with SageMaker Model Monitor

SageMaker Model Monitor helps you detect changes in input feature distributions and schema deviations by comparing production inference data to a baseline derived from training data.

Typical implementation steps:

1. Create a baseline from training data (or a validated representative sample).
2. Enable data capture on the endpoint or configure scheduled batch captures.
3. Configure Model Monitor jobs and alerts for distribution drift, missing values, and schema mismatches.
4. Feed Model Monitor reports and metrics into CloudWatch and your incident pipeline.
5. Investigate drift: decide whether to retrain, rollback, or correct upstream data issues.

This automation allows you to detect gradual or sudden drift and integrate the findings into retraining or data-quality workflows.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/GR4ncKaD2FS-haHS/images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/data-drift-detection-sagemaker-diagram.jpg?fit=max&auto=format&n=GR4ncKaD2FS-haHS&q=85&s=2aa086a682dc9a31046cd8d10d911973" alt="The image illustrates a process for detecting data drift using SageMaker Model Monitor, showing a flow from &#x22;Training Data Baseline&#x22; to &#x22;SageMaker Model Monitor&#x22; with accompanying icons." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/data-drift-detection-sagemaker-diagram.jpg" />
</Frame>

## Auditing with CloudTrail

CloudTrail records API activity (management and data-plane) and stores events in an S3 bucket (optionally encrypted). Those logs are searchable and analyzable with Athena, CloudWatch Logs Insights, or a SIEM.

Common audit use cases:

* Identify who deployed or updated a model artifact and when.
* Determine which principal invoked an endpoint at a specific time.
* Track changes to IAM policies and who authorized them.

Use the audit trail to produce compliance reports, conduct post-incident forensics, and prove reproducibility.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/GR4ncKaD2FS-haHS/images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/ml-system-auditing-cloudtrail-athena.jpg?fit=max&auto=format&n=GR4ncKaD2FS-haHS&q=85&s=4a0eb27d0439f127f9a23727db60ef12" alt="The image illustrates the process of auditing machine learning systems using CloudTrail, showing the flow from ML API calls to CloudTrail Logs and finally to an audit report using Athena/CloudWatch." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/ml-system-auditing-cloudtrail-athena.jpg" />
</Frame>

## Security and compliance best practices

Adopt layered controls to protect telemetry, model artifacts, and audit evidence:

* IAM: enforce least privilege and use service roles instead of long-lived credentials when possible.
* KMS: encrypt logs, model artifacts, and captured data at rest using AWS KMS keys with strict key policies and rotation.
* AWS Config: continuously evaluate resource configurations against organizational rules (for example, CloudTrail enabled, S3 buckets encrypted, endpoints in approved VPC subnets).
* Logging integrity: ensure CloudTrail and CloudWatch logs are centralized, immutable, and protected from tampering.

These controls not only secure telemetry and artifacts but also provide the governance necessary for audits and investigations.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/GR4ncKaD2FS-haHS/images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/security-compliance-iam-kms-aws-config.jpg?fit=max&auto=format&n=GR4ncKaD2FS-haHS&q=85&s=675f3fb1828e58f706691377312caa22" alt="The image depicts a flow diagram illustrating security and compliance for monitoring and auditing using IAM for access control, KMS for encryption of logs/data, and AWS Config for compliance checks." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/security-compliance-iam-kms-aws-config.jpg" />
</Frame>

<Callout icon="warning" color="#FF6B6B">
  Avoid these anti-patterns. They undermine observability, security, and compliance and make debugging or audits much harder.
</Callout>

## Anti-patterns to avoid

* No monitoring at all — you won’t be alerted when production degrades.
* Ignoring model and data drift — models degrade over time without detection.
* Not enabling CloudTrail — you lose the forensic history needed for investigations.
* Overly permissive IAM for monitoring — increases blast radius and insider risk.

Avoiding these anti-patterns preserves reliability and reduces security and compliance exposure.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/GR4ncKaD2FS-haHS/images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/anti-patterns-to-avoid-monitoring-cloudtrail.jpg?fit=max&auto=format&n=GR4ncKaD2FS-haHS&q=85&s=08ea5274c2e2b8d46286e7ebe6a3dc9f" alt="The image lists four anti-patterns to avoid: no monitoring enabled, ignoring model/data drift, not enabling CloudTrail (no audit), and over-permissive IAM for monitoring." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/anti-patterns-to-avoid-monitoring-cloudtrail.jpg" />
</Frame>

## Summary

* CloudWatch provides runtime telemetry, alarms, and dashboards for operational monitoring.
* SageMaker Model Monitor detects data and concept drift and reports model quality issues.
* CloudTrail records API activity to create an auditable history of actions.
* AWS Config enforces and reports on resource configuration compliance.
* IAM and KMS form the foundation for secure access control and encryption of telemetry and artifacts.

Use these components together to build a robust monitoring and auditing posture for production ML systems.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/GR4ncKaD2FS-haHS/images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/cloud-services-summary-cloudwatch-model-monitor.jpg?fit=max&auto=format&n=GR4ncKaD2FS-haHS&q=85&s=ea6f7d32b0a13a206adf40b33b0dcc8b" alt="The image is a summary slide listing five cloud services: CloudWatch, Model Monitor, CloudTrail, Config, and IAM + KMS, each with a brief description of their function." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/ML-Solution-Monitoring-Maintenance-and-Security/Monitoring-and-Auditing-ML-Systems/cloud-services-summary-cloudwatch-model-monitor.jpg" />
</Frame>

## Links and references

* AWS CloudWatch — [https://aws.amazon.com/cloudwatch/](https://aws.amazon.com/cloudwatch/)
* AWS CloudTrail — [https://aws.amazon.com/cloudtrail/](https://aws.amazon.com/cloudtrail/)
* AWS Config — [https://aws.amazon.com/config/](https://aws.amazon.com/config/)
* SageMaker Model Monitor — [https://docs.aws.amazon.com/sagemaker/latest/dg/model-monitor.html](https://docs.aws.amazon.com/sagemaker/latest/dg/model-monitor.html)
* Amazon Athena — [https://aws.amazon.com/athena/](https://aws.amazon.com/athena/)
* AWS KMS — [https://aws.amazon.com/kms/](https://aws.amazon.com/kms/)
* AWS IAM — [https://aws.amazon.com/iam/](https://aws.amazon.com/iam/)

Further reading: combine CloudWatch alarms, EventBridge rules, and Lambda automation with Model Monitor reports to create closed-loop pipelines that trigger retraining or sandboxed investigations when drift or anomalies are detected.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/aws-machine-learning-associates/module/e07ceb86-4976-4c8e-a6f8-3518534ec115/lesson/72f706ca-a363-4eda-afbe-d4b3af47c6c2" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/aws-machine-learning-associates/module/e07ceb86-4976-4c8e-a6f8-3518534ec115/lesson/e7386c83-0542-43df-99c4-b0148fc85fbd" />
</CardGroup>
