What is AWS CloudTrail?
Why Cost Optimization Matters
---
Primary Cost Components:
Cost Allocation Tags:
Get CloudTrail costs by usage type:
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}}"
})
Analyze CloudTrail usage patterns:
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "DAILY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"RESOURCE_ID\"}]",
"metrics": "[\"UsageQuantity\", \"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}}"
})
Get CloudTrail pricing information:
usePower("aws-cost-optimization", "awslabs.aws-pricing-mcp-server", "get_pricing", {
"service_code": "AWSCloudTrail",
"region": ["us-east-1", "us-west-2"],
"filters": [
{"Field": "productFamily", "Value": "API Request", "Type": "EQUALS"}
]
})
Monitor CloudTrail API activity:
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "get_metric_statistics", {
"namespace": "AWS/CloudTrailMetrics",
"metric_name": "EventCount",
"dimensions": [{"Name": "TrailName", "Value": "my-organization-trail"}],
"start_time": "2024-11-01T00:00:00Z",
"end_time": "2024-12-01T00:00:00Z",
"period": 3600,
"statistics": ["Sum"]
})
---
Strategy Overview:
First copy of management events is FREE, but additional copies cost $2.00 per 100,000 events. Eliminate duplicate trails to avoid unnecessary charges.
Implementation Steps:
1. Audit current trail configuration:
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}, \"And\": [{\"Dimensions\": {\"Key\": \"USAGE_TYPE\", \"Values\": [\"PaidEventsRecorded\"]}}]}"
})
2. Identify duplicate trails:
3. Implement organization trails:
4. Use S3 replication instead of multiple trails:
Strategy Overview:
All data events are charged at $0.10 per 100,000 events. Selective enablement and filtering can dramatically reduce costs.
Implementation Steps:
1. Analyze current data event costs:
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "DAILY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UsageQuantity\", \"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}, \"And\": [{\"Dimensions\": {\"Key\": \"USAGE_TYPE\", \"Values\": [\"DataEvents\"]}}]}"
})
2. Implement selective enablement:
3. Configure event selectors (up to 5 per trail):
4. Filter out high-volume events:
Strategy Overview:
CloudTrail Insights costs $0.35 per 100,000 events analyzed per Insight type. Enable selectively on critical trails only.
Implementation Steps:
1. Analyze Insights costs:
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}, \"And\": [{\"Dimensions\": {\"Key\": \"USAGE_TYPE\", \"Values\": [\"InsightEvents\"]}}]}"
})
2. Enable selectively:
3. Monitor Insights effectiveness:
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "get_metric_statistics", {
"namespace": "AWS/CloudTrailMetrics",
"metric_name": "InsightCount",
"dimensions": [{"Name": "TrailName", "Value": "critical-infrastructure-trail"}],
"start_time": "2024-11-01T00:00:00Z",
"end_time": "2024-12-01T00:00:00Z",
"period": 86400,
"statistics": ["Sum"]
})
Strategy Overview:
CloudTrail Lake has ingestion, retention, and analysis costs. Optimize through selective ingestion and query efficiency.
Implementation Steps:
1. Analyze CloudTrail Lake costs:
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}, \"And\": [{\"Dimensions\": {\"Key\": \"USAGE_TYPE\", \"Values\": [\"CloudTrailLake-Ingestion\", \"CloudTrailLake-Storage\", \"CloudTrailLake-Query\"]}}]}"
})
2. Optimize ingestion:
3. Choose appropriate retention:
4. Optimize queries:
Strategy Overview:
Optimize where CloudTrail logs are delivered and how long they're retained to minimize storage costs.
Implementation Steps:
1. Configure S3 lifecycle policies:
// Monitor S3 storage costs for CloudTrail logs
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"Amazon Simple Storage Service\"]}}"
})
2. Set up S3 transition rules:
3. Configure CloudWatch Logs retention:
4. Optimize delivery locations:
Cost-Performance Correlation:
Monitor CloudTrail usage patterns and costs to identify optimization opportunities and unusual activity.
Implementation Examples:
// Monitor CloudTrail cost-related alarms
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "describe_alarms", {
"alarm_name_prefix": "CloudTrailCost",
"state_value": "ALARM"
})
// Analyze CloudTrail event volume trends
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "get_metric_statistics", {
"namespace": "AWS/CloudTrailMetrics",
"metric_name": "EventCount",
"start_time": "2024-11-01T00:00:00Z",
"end_time": "2024-12-01T00:00:00Z",
"period": 86400,
"statistics": ["Sum"]
})
---
Problem Description:
Multiple trails capturing the same management events across regions or accounts, resulting in "PaidEventsRecorded" charges.
Detection:
// Look for paid management events charges
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}, \"And\": [{\"Dimensions\": {\"Key\": \"USAGE_TYPE\", \"Values\": [\"PaidEventsRecorded\"]}}]}"
})
Solution:
Problem Description:
Enabling data events on all S3 buckets or Lambda functions without filtering, generating massive volumes of low-value events.
Detection:
// Analyze data events volume and cost
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "DAILY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UsageQuantity\", \"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}, \"And\": [{\"Dimensions\": {\"Key\": \"USAGE_TYPE\", \"Values\": [\"DataEvents\"]}}]}"
})
Solution:
Problem Description:
Running broad queries without time constraints or filters, scanning unnecessary data and incurring high analysis costs.
Detection:
// Monitor CloudTrail Lake query costs
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "DAILY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UsageQuantity\", \"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}, \"And\": [{\"Dimensions\": {\"Key\": \"USAGE_TYPE\", \"Values\": [\"CloudTrailLake-Query\"]}}]}"
})
Solution:
---
Situation:
Large enterprise with 50 AWS accounts, each with regional CloudTrail trails. High costs from duplicate management events and unfiltered data events.
Analysis Approach:
// Step 1: Analyze current CloudTrail costs across organization
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-10-01",
"end_date": "2024-11-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"LINKED_ACCOUNT\"}, {\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}}"
})
// Step 2: Identify paid events (duplicate trails)
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-10-01",
"end_date": "2024-11-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"LINKED_ACCOUNT\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}, \"And\": [{\"Dimensions\": {\"Key\": \"USAGE_TYPE\", \"Values\": [\"PaidEventsRecorded\"]}]}"
})
// Step 3: Analyze data events volume
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-10-01",
"end_date": "2024-11-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UsageQuantity\", \"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}, \"And\": [{\"Dimensions\": {\"Key\": \"USAGE_TYPE\", \"Values\": [\"DataEvents\"]}]}"
})
Solution Implementation:
1. Consolidate to organization trail - Single trail for all management events
2. Eliminate duplicate trails - Remove 150+ regional trails across accounts
3. Selective data events - Enable only on production S3 buckets and critical Lambda functions
4. Filter high-volume events - Exclude KMS and routine RDS API events
Results:
Situation:
Financial services company with 7-year retention requirements using CloudTrail Lake. High ingestion and storage costs from unfiltered events.
Analysis Approach:
// Analyze CloudTrail Lake costs by component
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-09-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}, \"And\": [{\"Dimensions\": {\"Key\": \"USAGE_TYPE\", \"Values\": [\"CloudTrailLake-Ingestion\", \"CloudTrailLake-Storage\", \"CloudTrailLake-Query\"]}}]}"
})
Solution Implementation:
1. Filter ingestion events - Exclude KMS and RDS API events (60% volume reduction)
2. Optimize retention strategy - Use 7-year tiered pricing for compliance data
3. Query optimization - Implement time-constrained queries with specific filters
4. Selective event sources - Focus on security-relevant event sources only
Results:
---
Common Integration Patterns:
Cross-Service Optimization:
Analysis Commands:
// Analyze cross-service costs for CloudTrail ecosystem
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"SERVICE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\", \"Amazon Simple Storage Service\", \"Amazon CloudWatch Logs\", \"Amazon EventBridge\", \"AWS Config\"]}}"
})
---
Cost Metrics:
Usage Metrics:
Operational Metrics (via CloudWatch):
Budget Alerts:
// Monitor CloudTrail-specific budget performance
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "budgets", {
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}}"
})
Anomaly Detection:
// Set up anomaly monitoring for CloudTrail
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_anomaly", {
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"AWS CloudTrail\"]}}"
})
Operational Alerts:
// Monitor CloudTrail event volume spikes
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "describe_alarms", {
"alarm_name_prefix": "CloudTrail",
"state_value": "ALARM"
})
Key Visualizations:
Implementation:
// Get existing CloudTrail dashboards
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "list_dashboards", {})
// Retrieve specific dashboard configuration
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "get_dashboard", {
"dashboard_name": "CloudTrailCostOptimization"
})
---
---
---
Service Code: AWSCloudTrail
Last Updated: January 6, 2025
Review Cycle: Quarterly