All posts

Auditing & Accountability CloudTrail Query Runbooks

Efficient cloud auditing is increasingly critical for maintaining accountability and compliance. AWS CloudTrail provides unparalleled visibility into API activity across your account, but raw data alone is not enough. Transforming CloudTrail logs into actionable insights requires a structured approach. Query runbooks are the key to going beyond the raw log files and ensuring you can effectively monitor activity, detect anomalies, and meet compliance requirements. In this guide, you’ll uncover h

Free White Paper

AWS CloudTrail + Database Query Logging: The Complete Guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free. No spam. Unsubscribe anytime.

Efficient cloud auditing is increasingly critical for maintaining accountability and compliance. AWS CloudTrail provides unparalleled visibility into API activity across your account, but raw data alone is not enough. Transforming CloudTrail logs into actionable insights requires a structured approach. Query runbooks are the key to going beyond the raw log files and ensuring you can effectively monitor activity, detect anomalies, and meet compliance requirements.

In this guide, you’ll uncover how to create and use CloudTrail query runbooks to enhance auditing and accountability in your cloud workflows. Let’s break down the practical steps and best practices.

What Are CloudTrail Query Runbooks?

A CloudTrail query runbook is a documented process or automated script designed to make investigating CloudTrail logs consistent, efficient, and reliable. These runbooks often include predefined queries for common activities like identifying unauthorized access, seeing who modified critical resources, or checking compliance with access policies.

Runbooks can save engineers time by eliminating repetitive work and ensuring that responses to security or compliance issues follow best practices.

Why Use Query Runbooks?

  1. Consistency: You ensure repetitive tasks always get completed without variance.
  2. Speed: Prewritten queries remove the need to craft SQL-like scripts during an incident.
  3. Visibility: Queries help extract meaningful insights, such as unusual login attempts or privilege escalations.
  4. Accountability: Having a documented process makes it easier to report progress or findings to stakeholders.

With predefined scripts, you can focus on decision-making, instead of being bogged down by manual analysis.


Working with CloudTrail Logs

CloudTrail logs track AWS API requests, their source, who made them, and the actions performed. However, the sheer volume of logs can be overwhelming. To extract meaningful insights, you’ll need to use tools like AWS CloudTrail Insights, Athena, or query these logs directly in your cloud storage solution.

Types of Events in CloudTrail Logs

  • Management Events: Actions related to your resources, like creating or deleting an EC2 instance.
  • Data Events: Activities involving your data, like accessing an S3 bucket or executing SQL queries.
  • Insight Events: Detect unusual activity or deviations from baseline user behavior.

A robust query runbook can process each of these event types, ensuring you're compliant and secure.


Examples of CloudTrail Query Runbooks

Here are a few common scenarios with corresponding runbook approaches:

Continue reading? Get the full guide.

AWS CloudTrail + Database Query Logging: Architecture Patterns & Best Practices

Free. No spam. Unsubscribe anytime.

1. Detecting Unauthorized Access

  • WHAT: Query for API calls from unexpected IP ranges or geolocations.
  • WHY: Helps you spot potential compromises before they escalate.
  • HOW: Use a query to filter by SourceIPAddress and compare with known trusted IP blocks.

Sample Query:

SELECT eventName, awsRegion, sourceIPAddress
FROM cloudtrail_logs_table
WHERE eventTime >= 'YYYY-MM-DD'
 AND eventName = 'ConsoleLogin'
 AND sourceIPAddress NOT IN ('trusted-ip1', 'trusted-ip2');

2. Identifying Policy Changes

  • WHAT: Track activity that modifies IAM roles, groups, or permissions.
  • WHY: Ensures policy changes align with internal permissions strategy.
  • HOW: Query for changes made to specific IAM actions.

Sample Query:

SELECT eventName, userIdentity, requestParameters
FROM cloudtrail_logs_table
WHERE eventSource = 'iam.amazonaws.com'
 AND eventName IN ('PutRolePolicy', 'AttachGroupPolicy');

3. S3 Bucket Access Audit

  • WHAT: Surface unauthorized access to sensitive S3 buckets.
  • WHY: Protect data from being exposed or exfiltrated.
  • HOW: Look for GetObject events in your buckets during unusual hours.

Sample Query:

SELECT bucketName, eventName, eventSource, awsRegion
FROM cloudtrail_logs_table
WHERE eventSource = 's3.amazonaws.com'
 AND eventName = 'GetObject'
 AND eventTime BETWEEN '2023-10-01' AND '2023-10-02';

These predefined runbooks simplify the troubleshooting and monitoring processes.


Best Practices for CloudTrail Query Runbooks

1. Use Modular Queries:
Break down complex investigations into smaller, reusable pieces. For example, one query can isolate events by IP, while another checks for resource modifications. You can stack these later for more advanced analyses.

2. Organize and Document Your Runbooks:
Maintain version-controlled documentation or code repositories for query runbooks to ensure they stay updated as your cloud architecture evolves.

3. Automate Where Possible:
Integrate runbooks with alerting systems like AWS CloudWatch or third-party tools. For instance, run specific queries whenever an insight flag is raised.

4. Log Retention Settings:
Ensure your CloudTrail log retention meets compliance regulations. For example, finance or healthcare industries often require logs to be stored for extended periods.


Pair Query Runbooks with Streamlined Tools

Manually writing SQL queries or sifting through raw logs isn’t always the best use of engineering time. Tools exist to streamline these processes further, allowing you to get insights rapidly. That’s where solutions like Hoop.dev come in. Hoop.dev provides a centralized platform to automate query execution, visualize results, and implement your runbooks in minutes.

Why spend hours building and running queries individually? See how Hoop.dev can activate your first query workflow in just a few clicks and take charge of CloudTrail auditing today.

Get started

See hoop.dev in action

One gateway for every database, container, and AI agent. Deploy in minutes.

Get a demoMore posts