Skip to content

CloudTrail on AWS: best practices for auditing and investigation

Without a well-configured CloudTrail, investigating an AWS incident turns into guesswork. See what to record, what to protect, and how to analyze it.

Reading time
7 min
Published

CloudTrail is the audit trail of AWS. It records who did what, when, and from where, which is why it is the first source an investigation turns to when rebuilding the timeline of an incident. The problem is that many accounts rely only on the default event history, which keeps the last 90 days. There is no persistent trail, not every region is covered, and nothing protects the records against tampering.

CloudTrail only really helps if it is reliable at the moment that matters most, which is during an investigation. To get there, you need to decide which event types to record and how broadly, protect the files against changes and deletion (integrity, immutability, and encryption), and pick the few events that deserve an immediate alert. The rest of the log volume has to be organized in a way that lets you investigate without getting lost.

Multi-region and organization trails

Create a multi-region trail, which captures activity in every region, including the ones you do not use. This matters because attackers like to operate in the forgotten regions, where nobody looks. If the environment has several accounts, an organization trail centralizes the events of the whole structure in a single controlled destination.

Store the logs in a separate, restricted account, ideally a dedicated log account. That way, whoever compromises the production account cannot erase the trail that recorded what they did. On the destination bucket, harden the policy to deny deletion and to deny any write that does not come from CloudTrail, and consider Object Lock in compliance mode, which makes the files immutable for the retention period. After all, a log that the intruder can delete loses exactly the value it was supposed to have.

Management events and data events

Management events record control operations, such as creating a role, changing a policy, or opening a security group, and they are the bare minimum. Data events record operations on the data itself (reads and writes of S3 objects, Lambda invocations) and generate much higher volume and cost.

So keep management events always on and turn on data events selectively, only for the most sensitive buckets and functions. Enabling data events everywhere generates cost and noise. On the other hand, enabling them nowhere leaves a blind spot exactly where the data lives.

Integrity, encryption, and analysis

Enable log file integrity validation. It produces signed digest files that let you prove no record was altered or removed, and without that proof the evidence loses weight. Also encrypt the logs with a dedicated KMS key and restrict who can use that key.

A log that nobody queries does not help at all. Send CloudTrail to an analysis tool (CloudWatch Logs, a data lake with Athena, or a SIEM) and create queries and alerts for the critical events. If you do not want to build that analysis infrastructure yourself, CloudTrail Lake is the managed option from AWS: a repository with long retention and SQL queries.

Events that deserve an immediate alert

Coverage only turns into detection when some events trigger an alert right away, without waiting for someone to run a manual query. A small, well-chosen set avoids alert fatigue and already covers the signals most closely tied to compromise and to attempts at covering tracks.

  • Use of the root account, which should be extremely rare
  • StopLogging, or the deletion or modification of a CloudTrail trail
  • Creation of access keys and of new privileged users
  • Changes to the trust policy of a role, or attachment of broad policies
  • Disabling GuardDuty, Config, or KMS keys
  • Changes to SCPs and to the organization structure

Give the trail deactivation alert the highest severity, because that is usually the first step for someone who wants to act without leaving a record. Route these events to a channel with an owner and a response deadline, since a dashboard that nobody watches warns nobody.

Practical checklist

  • Create a multi-region trail that covers every region
  • Centralize the logs in a dedicated, restricted account
  • Keep management events always on
  • Enable data events on the most sensitive buckets and functions
  • Turn on log file integrity validation
  • Make the files immutable with a restrictive policy and Object Lock on the bucket
  • Encrypt the logs with a dedicated KMS key
  • Restrict who can stop, change, or delete the trail
  • Set a retention period that meets your investigation requirements
  • Alert on trail deactivation, root usage, and IAM changes
  • Run a real investigation as an exercise to validate coverage

Best practices

  • Treat disabling CloudTrail as a high-severity event
  • Keep the log account separate from the production environment
  • Use data events with judgment, where the data that matters lives
  • Have reusable investigation queries ready ahead of time
  • Set alerts for root usage and IAM changes
  • Document where the logs are and how to access them in the middle of an incident

Common mistakes

Relying only on the 90-day event history
Older incidents are left without evidence and the investigation stalls.
Trail limited to a single region
Malicious activity in the other regions goes unnoticed.
Logs in the production account itself, with no restrictions
Whoever compromises the account can erase the audit trail.
No integrity validation
There is no way to prove that the records were not tampered with.
Logs collected and never analyzed
Critical events raise no alert, and detection time shoots up.

Authorship and review

Cesar Gargiulo

CEO and founder of GUARDIASEC. Technical and editorial lead for the content published in this library.

Published on . Found a technical error? Write to [email protected] and we will correct it and keep a record of the change.

Frequently asked questions

Are CloudTrail and CloudWatch the same thing?
No. CloudTrail records API calls and administrative activity in the account, so it answers who did what. CloudWatch collects metrics and operational logs from resources and applications. Each one complements the other: CloudTrail can send events to CloudWatch Logs, and that is where you create the alerts.
Do I need to enable data events on every bucket?
That is not recommended. Data events on everything mean high volume, high cost, and a lot of noise. The balance lies in keeping management events always on and enabling data events only for the buckets and functions that hold sensitive data or are critical to operations.
How long should I keep CloudTrail logs?
It depends on your investigation requirements and on any contractual obligations. As a reference, many organizations keep at least one year, with older history in low-cost storage. What defines the period is the time that usually passes between a compromise and its discovery, and retention needs to cover that window.
How do I keep an attacker from disabling CloudTrail?
Centralize the logs in a separate account, use IAM and SCPs to restrict who can stop or change the trail, and create a high-severity alert for any deactivation event. Each piece covers part of the problem. Integrity validation helps prove tampering, Object Lock on the bucket keeps files from being deleted before the deadline, and the isolated log account keeps the evidence out of reach of whoever compromised production.
What is the difference between CloudTrail Lake and sending logs to Athena?
Both let you query events in SQL. The difference is that CloudTrail Lake is fully managed: you set the retention and start querying, without building a bucket, a catalog, and tables. With S3 and Athena you get more control and usually spend less at high volume, but you pay for it with the work of running that infrastructure. For many teams, Lake is the shortest path to a log base they can investigate from day one.

When to bring in specialist help

Organizing collection, retention, and detection around CloudTrail, and then validating it all with a real investigation, is security operations work. GUARDIASEC does this in its monitoring and response service, where we define the detection use cases and the investigation workflows.