logo
Menu
How to Optimize AWS CloudTrail Costs with Efficient Cloud Governance

How to Optimize AWS CloudTrail Costs with Efficient Cloud Governance

we'll explore strategies to optimize CloudTrail costs while maintaining effective governance and compliance.

Aneesh
Amazon Employee
Published Sep 24, 2024

Introduction

AWS CloudTrail offers two event types, Management Events and Data Events. Management Events, which capture control plane actions like creating or deleting Amazon S3 buckets, are free for the first copy delivered in each region. Additional copies of Management Events incur charges based on the number of events recorded.
Data Events, on the other hand, capture high-volume data plane actions such as reading or writing Amazon S3 objects, AWS Lambda function invocations, etc. Please refer here for all the data events .These events are charged based on the volume recorded, and costs can spike for workloads with substantial data plane activity.
When working with AWS CloudTrail, it's common to see duplicate trails. Sometimes, teams might create new trails without realizing one already exists. In some cases, automated templates or infrastructure-as-code setups have a default option to enable AWS CloudTrail, which might create duplicate trails. Sometimes, it will be a product use case you might need for compliance and governance purposes.

Cost Optimization Strategies

1) Ensure you have a single trail configured in each region to capture the free copy of Management Events. This provides essential governance and auditing capabilities without incurring additional charges.Review your trails and disable Management Event logging on any additional trails beyond the first copy. If duplicate copies are required for compliance purposes, consider replicating data between S3 buckets within the same region, which is typically more cost-effective than paying for duplicate event delivery.
In AWS Cost Explorer, you can filter the service to 'CloudTrail' and the usage type to '<Region>PaidEventsRecorded' to identify any duplicate trails cost
The following diagram shows the duplicate event cost in Cost Explorer
Filter PaidEventsRecorded from Usage Type
Figure 1 PaidEventsRecorded

2) Data events are often high volume activities. Instead of enabling Data Events across all resources, carefully evaluate your specific compliance and auditing requirements. Enable Data Events only for the resources and actions that are truly necessary, such as tracking object-level operations on critical S3 buckets or monitoring specific Lambda functions
In AWS Cost Explorer, you can filter the service to 'CloudTrail' and the usage type to '<Region>DataEventsRecorded' to identify Data Event cost for CloudTrail
The following diagram shows the Data Events cost in AWS Cost Explorer
DataEventsRecorded
Figure 2 DataEventsRecorded

3) AWS CloudTrail Event Selectors allow you to define fine-grained filters for the events you want to capture, further reducing the volume of recorded Data Events and associated costs. For example, you can configure a selector to log only specific Amazon S3 bucket delete operations instead of capturing all Amazon S3 data events. Another example, you can exclude Amazon RDS Data API events from your trails if you don't need them .Please refer How to optimize AWS CloudTrail costs by using advanced event selectors
The following diagram shows Advanced event selectors option
Advanced event selectors
Figure 3: Advanced event selectors

4) Evaluate your event delivery and storage options based on your planned usage and associated charges. For example, consider delivering events to Amazon S3 for long-term storage and analysis, while leveraging Amazon CloudWatch Logs for real-time monitoring and alerting.Define expiration rules for Amazon CloudWatch Log Groups and transition rules for Amazon S3 buckets to manage storage costs effectively. Configure retention periods to automatically delete log messages after a specified duration, and leverage object lifecycle management policies on AWS CloudTrail S3 buckets.
The following diagram shows the updated retention period based on the use case
Figure 4 CloudWatch Retention

5) Use Amazon Athena to analyze AWS CloudTrail logs and identify trends, troubleshoot operational issues, and optimize costs. Please refer How do I automatically create tables in Amazon Athena to search through AWS CloudTrail logs
The following example query shows AWS CloudTrail monthly cost increases

6) Resource-level permissions in CloudTrail provide fine-grained control over user access, allowing you to grant specific users permissions to view trail activity, create or delete trails, or perform other targeted operations, ensuring proper segregation of duties and access control. Please refer Identity-based policy examples for AWS CloudTrail
The following example shows a policy that grants read-only access to CloudTrail trails

Conclusion

Throughout this post, we have explored various strategies to optimize the costs associated with AWS CloudTrail.In summary, the key strategies we covered are as follows
  • Leverage Free Management Events
  • Minimize Duplicate Management Event Copies
  • Selectively Enable Data Events
  • Leverage Event Selectors
  • Optimize Storage Costs
By adopting these strategies, you can maximize the cost-efficiency of your AWS CloudTrail implementation while maintaining governance and compliance capabilities

 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments