AWS Cloud Security for AI Compliance: CloudTrail, IAM, and SCPs for ML Workloads
AI governance starts with infrastructure security. You cannot claim compliance for your ML models if the underlying cloud environment is not locked down. An unscoped IAM role on your SageMaker training job undermines every Model Card and Clarify report you produce.
This article covers the security foundation that every AWS AI governance program needs: CloudTrail for auditable trails, IAM for least-privilege access to SageMaker and Bedrock, Service Control Policies for organizational guardrails, and event-driven remediation for automated enforcement.
If you are looking for the broader AWS AI governance framework -- including Model Cards, lineage tracking, and bias detection -- start with the Complete Guide to AWS AI/ML Governance.
The Security Foundation for AI
AI workloads introduce security requirements that traditional cloud workloads do not have:
- Training data access must be audited and restricted. Training data often contains PII, proprietary business data, or licensed content.
- Model artifacts are intellectual property. Unauthorized access to model weights enables model theft (OWASP LLM10).
- Inference endpoints process live customer data. They need the same protections as any production API.
- Foundation model APIs (Bedrock) send your data to AWS-managed infrastructure. You need guardrails on what data leaves your VPC.
- ML pipelines run long-lived processes that create, transform, and deploy artifacts. Every step needs an audit trail.
The fundamental principle: treat ML workloads with the same rigor as your most sensitive production systems, because they are.
CloudTrail Configuration for ML Audit Trails
CloudTrail captures API calls for SageMaker and Bedrock. The default configuration captures management events (CreateModel, CreateEndpoint, DeleteModel) but misses critical data plane events.
What You Need to Capture
| Event Category | Examples | CloudTrail Setting |
|---|---|---|
| Management events | CreateTrainingJob, CreateModel, CreateEndpoint, UpdateEndpoint, DeleteEndpoint | Enabled by default |
| SageMaker data events | InvokeEndpoint, InvokeEndpointAsync | Requires data event logging |
| S3 data events | GetObject/PutObject on training data and model artifact buckets | Requires S3 data event logging |
| Bedrock management | CreateGuardrail, CreateModelCustomizationJob | Enabled by default |
| Bedrock data events | InvokeModel, InvokeModelWithResponseStream | Requires data event logging |
Enabling Data Events for SageMaker and Bedrock
# Enable CloudTrail data events for SageMaker endpoints
aws cloudtrail put-event-selectors \
--trail-name ml-governance-trail \
--advanced-event-selectors '[
{
"Name": "SageMakerInvokeEvents",
"FieldSelectors": [
{"Field": "eventCategory", "Equals": ["Data"]},
{"Field": "resources.type", "Equals": ["AWS::SageMaker::Endpoint"]}
]
},
{
"Name": "BedrockInvokeEvents",
"FieldSelectors": [
{"Field": "eventCategory", "Equals": ["Data"]},
{"Field": "resources.type", "Equals": ["AWS::Bedrock::Model"]}
]
},
{
"Name": "MLDataBucketAccess",
"FieldSelectors": [
{"Field": "eventCategory", "Equals": ["Data"]},
{"Field": "resources.type", "Equals": ["AWS::S3::Object"]},
{"Field": "resources.ARN", "StartsWith": [
"arn:aws:s3:::ml-data/",
"arn:aws:s3:::ml-artifacts/",
"arn:aws:s3:::ml-monitoring/"
]}
]
}
]'
Compliance Tip: CloudTrail data events for SageMaker endpoints and S3 training data buckets generate significant volume. Use CloudTrail Lake for long-term retention and SQL-based querying instead of raw S3 log files. Budget approximately $2.50 per 100,000 events ingested into CloudTrail Lake.
CloudTrail Lake for ML Audit Queries
CloudTrail Lake lets you run SQL queries across your audit trail. Here are the queries your auditor will want:
# Who accessed training data in the last 90 days?
aws cloudtrail-data start-query \
--query-statement "
SELECT
eventTime,
userIdentity.arn AS principal,
eventName,
requestParameters
FROM <event-data-store-id>
WHERE
eventSource = 's3.amazonaws.com'
AND eventName IN ('GetObject', 'PutObject', 'DeleteObject')
AND resources.ARN LIKE '%ml-data%'
AND eventTime > '2026-01-01 00:00:00'
ORDER BY eventTime DESC
"
# All SageMaker model deployments in the last quarter
aws cloudtrail-data start-query \
--query-statement "
SELECT
eventTime,
userIdentity.arn AS deployer,
eventName,
requestParameters
FROM <event-data-store-id>
WHERE
eventSource = 'sagemaker.amazonaws.com'
AND eventName IN ('CreateModel', 'CreateEndpoint', 'UpdateEndpoint')
AND eventTime > '2026-01-01 00:00:00'
ORDER BY eventTime DESC
"
These queries produce audit evidence for SOC 2 CC7.2 (security event evaluation) and CC8.1 (change management).
IAM Least Privilege for SageMaker and Bedrock
IAM is the most important security control for AWS AI workloads. It is also the one most frequently misconfigured. The pattern we see repeatedly: teams create a single SageMaker execution role with broad permissions and share it across all training jobs, processing jobs, and endpoints.
Common IAM Anti-Patterns for ML
| Anti-Pattern | Risk | Fix |
|---|---|---|
sagemaker:* on execution role |
Any training job can create endpoints, delete models, access any data | Scope to specific actions and resource ARN patterns |
s3:* on training data buckets |
Training jobs can read any S3 data, not just their assigned dataset | Scope to specific bucket/prefix per project |
bedrock:InvokeModel on * |
Any role can call any foundation model, including expensive ones | Scope to specific model IDs |
| Shared execution role across projects | One compromised project exposes all ML assets | One role per project/pipeline |
| No VPC requirement | Training jobs run on public internet by default | Require VPC via IAM condition keys |
Scoped IAM Policy for Bedrock Applications
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowSpecificModels",
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": [
"arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-5-sonnet*",
"arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed*"
]
},
{
"Sid": "AllowGuardrailUse",
"Effect": "Allow",
"Action": [
"bedrock:ApplyGuardrail"
],
"Resource": "arn:aws:bedrock:us-east-1:123456789:guardrail/production-*"
},
{
"Sid": "RequireGuardrail",
"Effect": "Deny",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": "*",
"Condition": {
"StringNotLike": {
"bedrock:GuardrailIdentifier": "arn:aws:bedrock:us-east-1:123456789:guardrail/production-*"
}
}
},
{
"Sid": "DenyModelCustomization",
"Effect": "Deny",
"Action": [
"bedrock:CreateModelCustomizationJob",
"bedrock:CreateProvisionedModelThroughput"
],
"Resource": "*"
}
]
}
This policy does four things:
- Allows invocation of only specific foundation models (cost control and governance)
- Allows use of production guardrails
- Denies any model invocation that does not use a guardrail (forces compliance)
- Denies model customization (fine-tuning requires separate, elevated permissions)
Key Takeaway: The
RequireGuardraildeny statement is the most important control here. It ensures that no Bedrock invocation bypasses your content and PII filters. This is direct evidence for NIST AI RMF Govern 1.1 (policies implemented effectively).
Service Control Policies for AI Governance
SCPs are organization-level guardrails that apply across all accounts in your AWS Organization. They are the outermost security boundary and cannot be overridden by individual account IAM policies.
SCP: Restrict AI Services to Approved Regions
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyAIServicesOutsideApprovedRegions",
"Effect": "Deny",
"Action": [
"sagemaker:*",
"bedrock:*"
],
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:RequestedRegion": ["us-east-1", "us-west-2"]
}
}
}
]
}
SCP: Require Encryption for All ML Workloads
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyUnencryptedSageMakerVolumes",
"Effect": "Deny",
"Action": [
"sagemaker:CreateTrainingJob",
"sagemaker:CreateProcessingJob",
"sagemaker:CreateTransformJob",
"sagemaker:CreateNotebookInstance"
],
"Resource": "*",
"Condition": {
"Null": {
"sagemaker:VolumeKmsKeyId": "true"
}
}
},
{
"Sid": "DenyUnencryptedSageMakerEndpoints",
"Effect": "Deny",
"Action": "sagemaker:CreateEndpointConfig",
"Resource": "*",
"Condition": {
"Null": {
"sagemaker:VolumeKmsKeyId": "true"
}
}
}
]
}
SCPs provide evidence for SOC 2 CC6.1 (logical access at the organizational level), ISO 42001 A.5 (organizational controls), and NIST AI RMF Govern 5.1 (organizational risk policies applied to AI).
CloudWatch and X-Ray for ML Observability
Audit trails tell you what happened. Observability tells you what is happening right now. For ML workloads, you need both.
Key CloudWatch Alarms for AI Compliance
# Alarm: SageMaker endpoint error rate exceeds threshold
aws cloudwatch put-metric-alarm \
--alarm-name "churn-v3-endpoint-error-rate" \
--alarm-description "Alert if endpoint error rate exceeds 5%" \
--metric-name "Invocation5XXErrors" \
--namespace "AWS/SageMaker" \
--dimensions Name=EndpointName,Value=churn-predictor-v3 \
--statistic Sum \
--period 300 \
--threshold 5 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 2 \
--alarm-actions "arn:aws:sns:us-east-1:123456789:ml-governance-alerts"
# Alarm: Bedrock throttling indicates capacity/cost issues
aws cloudwatch put-metric-alarm \
--alarm-name "bedrock-invocation-throttles" \
--alarm-description "Alert if Bedrock throttling exceeds threshold" \
--metric-name "InvocationThrottles" \
--namespace "AWS/Bedrock" \
--statistic Sum \
--period 300 \
--threshold 10 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 1 \
--alarm-actions "arn:aws:sns:us-east-1:123456789:ml-governance-alerts"
X-Ray Distributed Tracing for ML Inference
X-Ray provides distributed tracing for ML inference pipelines. When your application calls Bedrock, preprocesses the response, and stores results, X-Ray traces the entire flow. This is especially valuable for debugging latency issues and demonstrating to auditors that you have end-to-end visibility into your AI workflows.
Key X-Ray patterns for AI compliance:
- Trace every Bedrock invocation -- X-Ray segments capture latency, input/output token counts, and error codes for each foundation model call
- Trace preprocessing pipelines -- if you run PII scrubbing, content filtering, or embedding generation before calling Bedrock, each step should be a subsegment
- Annotate traces with compliance metadata -- add annotations for
model_id,guardrail_id, anddata_classificationso you can filter traces by compliance-relevant attributes - Set up sampling rules -- for high-volume inference endpoints, configure sampling to capture 100% of error traces and a representative sample of successful traces
X-Ray trace maps become evidence for SOC 2 CC7.1 by demonstrating that you have real-time visibility into your AI system's operational behavior, not just its API call history.
Compliance Tip: CloudWatch alarm history is compliance evidence. Export alarm state changes quarterly and include them in your SOC 2 evidence package under CC7.1 (system monitoring). The existence of alarms proves the monitoring control exists. Alarm triggers and responses prove the control operates effectively.
VPC Endpoints and Network Isolation
By default, SageMaker training jobs and Bedrock API calls route through the public internet. For compliance -- especially SOC 2 CC6.7 (data transmission controls) and regulated industries -- you need network isolation.
VPC Endpoints for SageMaker and Bedrock
# Create VPC endpoint for SageMaker API
aws ec2 create-vpc-endpoint \
--vpc-id vpc-ml-production \
--service-name com.amazonaws.us-east-1.sagemaker.api \
--vpc-endpoint-type Interface \
--subnet-ids subnet-ml-private-1a subnet-ml-private-1b \
--security-group-ids sg-sagemaker-endpoint \
--private-dns-enabled
# Create VPC endpoint for SageMaker Runtime (inference)
aws ec2 create-vpc-endpoint \
--vpc-id vpc-ml-production \
--service-name com.amazonaws.us-east-1.sagemaker.runtime \
--vpc-endpoint-type Interface \
--subnet-ids subnet-ml-private-1a subnet-ml-private-1b \
--security-group-ids sg-sagemaker-endpoint \
--private-dns-enabled
# Create VPC endpoint for Bedrock Runtime
aws ec2 create-vpc-endpoint \
--vpc-id vpc-ml-production \
--service-name com.amazonaws.us-east-1.bedrock-runtime \
--vpc-endpoint-type Interface \
--subnet-ids subnet-ml-private-1a subnet-ml-private-1b \
--security-group-ids sg-bedrock-endpoint \
--private-dns-enabled
With VPC endpoints in place, all SageMaker and Bedrock traffic stays within the AWS network and never traverses the public internet. Combined with security groups that restrict which subnets can reach these endpoints, you achieve network-level isolation for your AI workloads.
Key Takeaway: VPC endpoints are often overlooked in AI governance, but they are a direct control for SOC 2 CC6.7 (data transmission), NIST 800-53 SC-7 (boundary protection), and are increasingly expected by auditors for any workload processing sensitive data. Document your VPC endpoint configuration as evidence.
EventBridge Automated Remediation
Automated remediation closes the loop between detection and response. Without it, a CloudTrail alert about an unauthorized SageMaker endpoint creation sits in a Slack channel until someone notices.
Example: Block Unauthorized Model Deployments
# Lambda function triggered by EventBridge when a SageMaker endpoint
# is created without required tags
import boto3
import json
import os
sagemaker = boto3.client("sagemaker")
sns = boto3.client("sns")
REQUIRED_TAGS = ["compliance-framework", "model-card-arn", "data-classification"]
ALERT_TOPIC = os.environ["ALERT_TOPIC_ARN"]
def handler(event, context):
endpoint_name = event["detail"]["EndpointName"]
endpoint_arn = event["detail"]["EndpointArn"]
# Check if endpoint has required governance tags
tags_response = sagemaker.list_tags(ResourceArn=endpoint_arn)
existing_tags = {t["Key"] for t in tags_response["Tags"]}
missing_tags = [t for t in REQUIRED_TAGS if t not in existing_tags]
if missing_tags:
# Delete the non-compliant endpoint
sagemaker.delete_endpoint(EndpointName=endpoint_name)
sns.publish(
TopicArn=ALERT_TOPIC,
Subject=f"Non-compliant endpoint deleted: {endpoint_name}",
Message=json.dumps({
"action": "endpoint_deleted",
"endpoint": endpoint_name,
"reason": "Missing required governance tags",
"missing_tags": missing_tags,
"required_tags": REQUIRED_TAGS,
"remediation": "Add required tags and redeploy",
}),
)
return {
"statusCode": 200,
"action": "deleted",
"missing_tags": missing_tags,
}
return {"statusCode": 200, "action": "compliant"}
This pattern -- detect, remediate, notify -- is the core of automated compliance enforcement. Each execution produces an evidence artifact: the Lambda invocation log showing what was detected, what action was taken, and who was notified.
Compliance Framework Mapping
| Security Control | SOC 2 | NIST AI RMF | NIST 800-53 | ISO 42001 |
|---|---|---|---|---|
| CloudTrail for ML API logging | CC7.2 | Govern 1.1 | AU-2, AU-3, AU-12 | A.12.4 |
| CloudTrail data events for training data | CC7.2 | MS.2.1 | AU-2 | 8.6 |
| IAM least privilege for SageMaker | CC6.1, CC6.3 | Govern 1.1 | AC-6 | A.9.1 |
| IAM least privilege for Bedrock | CC6.1 | Govern 6.1 | AC-6 | A.9.1 |
| Guardrail enforcement via IAM deny | CC6.1 | Govern 1.1 | AC-3 | 8.5 |
| SCPs for region restriction | CC6.1 | Govern 5.1 | AC-3 | A.5 |
| SCPs for encryption enforcement | CC6.7 | -- | SC-28 | A.10.1 |
| CloudWatch alarms for ML endpoints | CC7.1 | Manage 2.4 | SI-4 | 9.3 |
| X-Ray distributed tracing | CC7.1 | Manage 2.4 | SI-4 | 9.3 |
| EventBridge automated remediation | CC7.2 | Manage 3.1 | IR-4 | 10.1 |
Related Articles
- Complete Guide to AWS AI/ML Governance -- the pillar article covering the full 10-pillar framework
- SageMaker Model Cards for Compliance -- documenting models for SOC 2 and EU AI Act
- SageMaker ML Lineage Tracking -- end-to-end model provenance