AWS CloudTrail: Tracking AWS API Activity
Learn how AWS CloudTrail records account activity and API events, helping cloud engineers with auditing, security investigations, troubleshooting, and compliance.
Series: My 90-Day AWS & DevOps Learning Journey (30 articles)
- …
- 12AWS CloudTrail: Tracking AWS API Activity This article
# AWS CloudTrail: Tracking AWS API Activity
When working with AWS, many different actions happen inside an account.
For example:
* Someone creates an EC2 instance.
* A user changes an IAM policy.
* An S3 bucket is modified.
* A security group is updated.
* An AWS resource is deleted.
* A user changes an IAM policy.
* An S3 bucket is modified.
* A security group is updated.
* An AWS resource is deleted.
In a real-world environment, it is important to know **who performed an action, what action was performed, and when it happened**.
This is where **AWS CloudTrail** becomes useful.
## What Is AWS CloudTrail?
AWS CloudTrail is a service that helps record and monitor activity within an AWS account.
It records information about many AWS API calls and account activities.
A simplified example is:
```text
User / Application
↓
AWS API Request
↓
AWS Service
↓
CloudTrail Records Activity
```
User / Application
↓
AWS API Request
↓
AWS Service
↓
CloudTrail Records Activity
```
CloudTrail can help organizations investigate changes and understand activity within their AWS environments.
## What Information Does CloudTrail Record?
A CloudTrail event can contain information such as:
* Who made the request
* What action was performed
* When the action occurred
* Which AWS service was accessed
* Which resource was involved
* Where the request came from
* Whether the request was successful
* What action was performed
* When the action occurred
* Which AWS service was accessed
* Which resource was involved
* Where the request came from
* Whether the request was successful
For example:
```text
User: Developer
Action: RunInstances
Service: EC2
Time: 10:30 AM
Result: Success
```
User: Developer
Action: RunInstances
Service: EC2
Time: 10:30 AM
Result: Success
```
This information can be useful when investigating unexpected changes.
## CloudTrail Events
An important concept to understand is the **CloudTrail event**.
An event represents an activity recorded by CloudTrail.
For example, if someone creates an EC2 instance, CloudTrail may record an event describing that API activity.
Another example:
```text
IAM User
↓
Changes IAM Policy
↓
CloudTrail
↓
Event Recorded
```
IAM User
↓
Changes IAM Policy
↓
CloudTrail
↓
Event Recorded
```
Later, an administrator can investigate the recorded activity.
## CloudTrail and IAM
CloudTrail and **AWS Identity and Access Management (IAM)** work well together.
IAM controls **who can perform actions**.
CloudTrail helps record **what actions were performed**.
Think of it like this:
```text
IAM
↓
Controls Access
IAM
↓
Controls Access
CloudTrail
↓
Records Activity
```
↓
Records Activity
```
For example, IAM may allow a user to create EC2 instances, while CloudTrail can record when that user actually creates one.
This distinction is important when learning AWS security.
## CloudTrail and Amazon S3
CloudTrail event information can be stored in Amazon S3 for longer-term retention and analysis.
A simplified architecture can look like:
```text
AWS Account
↓
CloudTrail
↓
S3 Bucket
↓
Long-Term Storage
```
AWS Account
↓
CloudTrail
↓
S3 Bucket
↓
Long-Term Storage
```
Storing logs in S3 can be useful when organizations need to retain activity records for auditing or investigation.
## CloudTrail and CloudWatch
CloudTrail and CloudWatch are both monitoring-related services, but they have different purposes.
**CloudWatch** focuses primarily on monitoring metrics, logs, and operational health.
**CloudTrail** focuses on recording AWS account activity and API events.
A simple comparison:
```text
CloudWatch
→ "How is my application or resource performing?"
CloudWatch
→ "How is my application or resource performing?"
CloudTrail
→ "What activity happened in my AWS account?"
```
→ "What activity happened in my AWS account?"
```
For example:
If an EC2 server has unusually high CPU usage, CloudWatch can help monitor the CPU metric.
If someone changes the EC2 configuration, CloudTrail can help identify the API activity associated with that change.
## CloudTrail for Security Investigation
Imagine that an S3 bucket configuration suddenly changes.
A security or cloud engineer may need to determine:
1. What changed?
2. When did it change?
3. Which identity made the change?
4. Which API action was used?
5. Was the change successful?
2. When did it change?
3. Which identity made the change?
4. Which API action was used?
5. Was the change successful?
CloudTrail records can provide valuable information for this type of investigation.
A simplified workflow is:
```text
Unexpected Change
↓
Check CloudTrail
↓
Find Event
↓
Identify API Activity
↓
Investigate
```
Unexpected Change
↓
Check CloudTrail
↓
Find Event
↓
Identify API Activity
↓
Investigate
```
## CloudTrail in DevOps
CloudTrail is also useful for DevOps teams.
DevOps environments often use automation tools and CI/CD pipelines to create and modify infrastructure.
For example:
```text
Developer
↓
CI/CD Pipeline
↓
AWS API
↓
Cloud Resources
↓
CloudTrail
```
Developer
↓
CI/CD Pipeline
↓
AWS API
↓
Cloud Resources
↓
CloudTrail
```
If an automated deployment changes an AWS resource, CloudTrail can provide an activity record that helps with troubleshooting and auditing.
This becomes particularly useful when many people and automation systems are working within the same AWS account.
## CloudTrail and Compliance
Organizations may need to maintain records of activity for security and compliance purposes.
CloudTrail can support these requirements by providing an audit trail of AWS account activity.
However, the exact retention, monitoring, and compliance configuration depends on the organization's requirements.
CloudTrail should therefore be considered part of a broader security and logging strategy rather than a complete security solution by itself.
## A Simple AWS Security Architecture
CloudTrail can work alongside other AWS services:
```text
AWS Account
|
+-------------+-------------+
| | |
IAM EC2 S3
| | |
+-------------+-------------+
|
CloudTrail
|
Activity Logs
|
S3 / Analysis
```
AWS Account
|
+-------------+-------------+
| | |
IAM EC2 S3
| | |
+-------------+-------------+
|
CloudTrail
|
Activity Logs
|
S3 / Analysis
```
This provides better visibility into account activity.
## CloudTrail vs CloudWatch
This is a common beginner question.
| Feature | CloudTrail | CloudWatch |
| -------------------- | ------------------------ | ---------------------------- |
| Main purpose | API/account activity | Monitoring and observability |
| Focus | Who did what | How resources are performing |
| Records API activity | Yes | Not its primary purpose |
| Metrics | Not its primary focus | Yes |
| Alarms | Not its primary function | Yes |
| Logs | Event records | Application/service logs |
| -------------------- | ------------------------ | ---------------------------- |
| Main purpose | API/account activity | Monitoring and observability |
| Focus | Who did what | How resources are performing |
| Records API activity | Yes | Not its primary purpose |
| Metrics | Not its primary focus | Yes |
| Alarms | Not its primary function | Yes |
| Logs | Event records | Application/service logs |
The two services can complement each other rather than replacing one another.
## Why CloudTrail Matters for Cloud Engineers
As a beginner, it is easy to focus only on creating AWS resources.
But real cloud environments also require:
* Security
* Auditing
* Monitoring
* Troubleshooting
* Accountability
* Visibility
* Auditing
* Monitoring
* Troubleshooting
* Accountability
* Visibility
CloudTrail helps cloud engineers understand activity happening inside an AWS environment.
## Key Takeaways
The important CloudTrail concepts to remember are:
* **CloudTrail records AWS account activity.**
* It records many AWS API events.
* Events can contain information about the user, action, resource, and time.
* CloudTrail is useful for auditing and security investigations.
* CloudTrail can work with Amazon S3 for log storage.
* CloudTrail and CloudWatch have different primary purposes.
* IAM controls access, while CloudTrail records activity.
* CloudTrail is useful in DevOps and automated environments.
* It records many AWS API events.
* Events can contain information about the user, action, resource, and time.
* CloudTrail is useful for auditing and security investigations.
* CloudTrail can work with Amazon S3 for log storage.
* CloudTrail and CloudWatch have different primary purposes.
* IAM controls access, while CloudTrail records activity.
* CloudTrail is useful in DevOps and automated environments.
As I continue learning AWS, I'm realizing that managing cloud infrastructure is not only about creating resources. **Knowing what happened inside the environment is equally important for security, troubleshooting, and reliable operations.**
Series: My 90-Day AWS & DevOps Learning Journey (30 articles)
- …
- 12AWS CloudTrail: Tracking AWS API Activity This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article