Lesson 2 of 4 Monitoring and Governance

Recording API Activity with AWS CloudTrail

This lesson explains how AWS CloudTrail records the API calls made in an account, answering who did what, when and from where, for auditing, security investigations and troubleshooting.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose the service that answers each question.
  • Distinguish event history from trails.
  • Describe how the audit trail is protected from tampering.

Which service answers which question

CloudTrail, Config and related services are frequently confused. Each answers a different question, as the following table shows.

ServiceAnswers
AWS CloudTrailWho made an API call, what, when and from where
AWS ConfigWhat a resource looked like at a point in time, and whether it complied
AWS X-RayWhere requests spend time across distributed services
Amazon CloudWatchHow resources and applications are performing
Trusted AdvisorCost, performance, security, fault tolerance and quota checks
AWS Health DashboardAWS events affecting your resources
Match the pairs

Which service answers?

Exam skills 2.2.3 · 1.3.1

Match each question with the service that answers it.

Log in to try this activity Interactive activities are free with an account.

Event history and trails

AWS CloudTrail records API activity in several ways. The event history keeps the last 90 days of management events, free and with no setup. Trails deliver events to Amazon S3, and optionally to CloudWatch Logs, for as long as the customer keeps them; an organisation trail covers every account and Region in the organisation.

Two kinds of event must be enabled separately: data events, such as S3 object operations and Lambda invocations, which are numerous and charged, and Insights events, which flag unusual API activity. Trail logs in S3 are queried with SQL through Amazon Athena. CloudTrail Lake, a managed event store queried with SQL, closed to new customers on 31 May 2026, so new designs use Athena over trail logs.

Protecting the audit trail

An audit trail is only trustworthy if it cannot be altered or stopped by the people it records. Log file integrity validation creates digest files that prove whether log files have been changed or deleted since delivery. Logs should be delivered to a separate log archive account, in a bucket with versioning and Object Lock, so administrators of workload accounts cannot delete them.

A service control policy that denies cloudtrail:StopLogging and cloudtrail:DeleteTrail stops anyone in member accounts from turning logging off, and encrypting log files with a customer managed KMS key adds control over who can read them.

The following diagram shows an organisation trail with the protections described above.

A protected organisation trail. An organisation trail records API activity in every account and Region and delivers it to a bucket in a separate log archive account, with versioning and Object Lock, and log file integrity validation. An SCP denies StopLogging and DeleteTrail in member accounts, and Athena queries the logs with SQL.
Because the logs live in another account, administrators of the member accounts cannot delete them.
Select all that apply

A trustworthy audit trail

Exam skills 1.1.4 · 1.3.6

Identify the controls that protect CloudTrail logs.

Log in to try this activity Interactive activities are free with an account.
Worked example

Three questions after an incident

Each question that arises after a security incident is answered by a particular service. The following table identifies the appropriate service for three such questions.

QuestionService
Who opened port 22 to the world on the database security group?CloudTrail
What did the security group look like before the change, and is it compliant now?AWS Config
Why are checkout requests slow, and which service is the bottleneck?AWS X-Ray

The company then adds an AWS Config rule (restricted-ssh) with automatic remediation, so a security group opened to the world is fixed within minutes, whoever opens it.

Check yourself

How long does CloudTrail event history keep management events?

Show answer

90 days. A trail delivering to S3 is needed to keep events longer or to record data events.

Exam Tips

Remember for the exam

  • To find out who deleted a resource, use CloudTrail.
  • To keep API history longer than 90 days, create a trail that delivers to S3.
  • To detect tampering with log files, use CloudTrail log file integrity validation.
  • To stop anyone disabling CloudTrail, use an SCP denying cloudtrail:StopLogging and cloudtrail:DeleteTrail.
  • To record S3 object-level access, enable data events.