CloudTrail for API auditing in AWS - Time & Space Complexity
When using CloudTrail to audit API calls, it's important to understand how the number of recorded events grows as more API activity happens.
We want to know how the work CloudTrail does changes when more API calls are made.
Analyze the time complexity of the following operation sequence.
aws cloudtrail create-trail --name MyTrail --s3-bucket-name my-bucket
aws cloudtrail start-logging --name MyTrail
# API calls happen in the account
# CloudTrail records each API call event
aws cloudtrail lookup-events --max-results 50
This sequence creates a trail, starts logging API calls, and then queries the recorded events.
- Primary operation: Recording each API call event by CloudTrail.
- How many times: Once per API call made in the account.
As the number of API calls increases, CloudTrail records more events, so the work grows with the number of calls.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 event records created |
| 100 | 100 event records created |
| 1000 | 1000 event records created |
Pattern observation: The number of recorded events grows directly with the number of API calls.
Time Complexity: O(n)
This means the work CloudTrail does grows linearly as more API calls happen.
[X] Wrong: "CloudTrail records all API calls instantly without extra work as calls increase."
[OK] Correct: Each API call generates a new event to record, so more calls mean more work for CloudTrail.
Understanding how logging scales with activity helps you design systems that monitor usage efficiently and predict costs.
"What if CloudTrail was configured to log only specific API calls? How would that affect the time complexity?"
Practice
Solution
Step 1: Understand CloudTrail's role
CloudTrail is designed to record all API calls made in an AWS account for auditing and security purposes.Step 2: Compare other options
The other options describe other AWS services or functions unrelated to CloudTrail's main purpose.Final Answer:
To record API calls for auditing and security -> Option CQuick Check:
CloudTrail = API call recording [OK]
- Confusing CloudTrail with S3 storage
- Thinking CloudTrail manages permissions
- Assuming CloudTrail monitors server health
Solution
Step 1: Identify CloudTrail log storage
CloudTrail stores its logs in an Amazon S3 bucket that you specify during setup.Step 2: Eliminate other services
Amazon EC2 is for virtual servers, RDS is for databases, and Lambda runs code; none store CloudTrail logs.Final Answer:
Amazon S3 -> Option AQuick Check:
CloudTrail logs go to S3 buckets [OK]
- Choosing EC2 as storage
- Confusing Lambda with log storage
- Selecting RDS for logs
{"ReadWriteType": "WriteOnly"}Which API calls will CloudTrail log?
Solution
Step 1: Understand ReadWriteType setting
The "WriteOnly" setting means CloudTrail logs only API calls that change resources (write operations).Step 2: Interpret options
This logs only write API calls. Read-only and both read/write options include read calls, which are excluded. 'No API calls' means no logging, which is incorrect.Final Answer:
Only write API calls -> Option BQuick Check:
WriteOnly = write calls logged [OK]
- Confusing WriteOnly with ReadOnly
- Assuming both read and write are logged
- Thinking no calls are logged
Solution
Step 1: Check S3 bucket permissions
If the bucket policy blocks CloudTrail, logs cannot be delivered, causing no logs to appear.Step 2: Eliminate incorrect causes
CloudTrail does support logging API calls, logs are not stored on EC2 instances by default, and it logs both read and write API calls by default (not only read).Final Answer:
The S3 bucket policy blocks CloudTrail from writing logs -> Option DQuick Check:
Bucket policy must allow CloudTrail writes [OK]
- Assuming CloudTrail logs to EC2
- Thinking CloudTrail doesn't log API calls
- Believing default logs are read-only
Solution
Step 1: Understand management events
Management events track control plane operations like creating or deleting resources.Step 2: Select correct event selector
Setting event selectors to log only management events ensures auditing of these API calls.Step 3: Eliminate other options
Enable CloudTrail with logging only data events on S3 buckets logs data events, not management events. Disable CloudTrail and use CloudWatch logs instead disables CloudTrail, losing audit logs. Enable CloudTrail with event selectors set to log only read-only events logs only read-only events, missing write management events.Final Answer:
Enable CloudTrail with event selectors set to log only management events -> Option AQuick Check:
Management events = control plane API logs [OK]
- Confusing data events with management events
- Disabling CloudTrail thinking CloudWatch suffices
- Logging only read-only events misses writes
Ready to prove it?
Pass the test and this pattern moves unknown
