Data Security and Governance · Topic 6 of 7

Audit Logging on AWS

Prepare logs for audit with CloudTrail and CloudTrail Lake, CloudWatch Logs, S3 and Redshift audit logs, retention, integrity checks and Athena.

  • 5 min
In a nutshell
  • CloudTrail records API calls. Event history covers 90 days of management events.
  • A trail to S3 is needed for longer retention. Data events must be enabled.
  • Turn on log file integrity validation and protect the log bucket.

What it is

An audit log is a trustworthy record of who did what, when and from where. Auditors, security teams and regulators use it to check that rules were followed and to investigate incidents.

For a data engineer the work is to switch the right logs on, store them safely for the required time, and make them searchable.

AWS activityAPI calls, queriesrecorded byCloudTrailevent historydelivered toS3 and CloudWatch Logsretainedqueried withAthena or Logs Insightsaudit evidence

How it works

AWS CloudTrail

CloudTrail records API activity in your account. Each event shows the caller identity, the time, the source IP address, the action and the parameters. The last 90 days of management events are visible in Event history without any setup.

For longer retention, create a trail that delivers events to an S3 bucket, and optionally to CloudWatch Logs. A trail can cover all Regions and, with AWS Organizations, all accounts in the organization.

Event typeWhat it coversDefault
Management eventsControl plane actions such as creating a bucket or changing a policyLogged by a trail
Data eventsData plane actions such as S3 object reads, Lambda invokes and DynamoDB item accessOff, must be enabled, higher volume and cost
Insights eventsUnusual API activity patternsOff, optional

Data events matter for data platforms because they show who read which object. Enable them for sensitive buckets and tables, and filter with event selectors to control cost.

aws cloudtrail put-event-selectors --trail-name org-trail \
  --advanced-event-selectors '[{"Name":"S3 data events for lake","FieldSelectors":[
    {"Field":"eventCategory","Equals":["Data"]},
    {"Field":"resources.type","Equals":["AWS::S3::Object"]},
    {"Field":"resources.ARN","StartsWith":["arn:aws:s3:::my-lake/"]}]}]'

Integrity and protection

Turn on log file integrity validation, which lets you verify with digest files that log files were not changed or deleted. Store logs in a separate, locked down account or bucket, encrypt them with KMS, and use S3 Object Lock for write once retention. Limit who can delete or edit trails.

CloudTrail Lake

CloudTrail Lake stores events in an event data store and lets you run SQL queries on them directly, with a retention period that you choose. It suits teams that want searchable audit data without building their own pipeline.

CloudWatch Logs

Services such as Lambda, Glue, EMR, MWAA, Redshift and API Gateway send logs to CloudWatch Logs. Set retention for each log group to match policy.

Logs Insights queries recent data interactively. Subscription filters stream logs to Kinesis Data Streams, Firehose or Lambda in near real time, for example to ship them to S3 or OpenSearch.

Service specific audit logs

SourceWhat it recordsWhere
S3 server access logsRequests to a bucketAnother S3 bucket
Amazon Redshift audit loggingConnection log, user log, user activity logS3 or CloudWatch Logs
VPC Flow LogsNetwork traffic metadataS3, CloudWatch Logs or Firehose
Amazon OpenSearch ServiceAudit logs when fine grained access control is onCloudWatch Logs
AWS ConfigResource configuration history and complianceS3 and Config
Lake FormationPermission changes and data accessThrough CloudTrail
Amazon AthenaQuery history and workgroup metricsAthena and CloudWatch

Redshift's user activity log needs the parameter enable_user_activity_logging to be on in the cluster parameter group, and it also needs audit logging switched on. Without it, the SQL text of queries is not recorded in the audit logs.

Analyzing logs at scale

For large volumes, keep logs in S3 as compressed, partitioned files and query them with Athena. Create the table once with partition projection, and the date partitions stay current.

For quick searches use CloudWatch Logs Insights. For dashboards and search, send logs to OpenSearch Service. For real time alerts on a pattern, use a metric filter and an alarm, or an EventBridge rule on CloudTrail events.

Retention and compliance

Decide retention from legal and business rules. Use lifecycle rules to move older logs to cheaper storage classes and expire them at the end of the retention period. Keep a consistent time format and include the account, Region and resource in each record, so investigations can follow an event across systems.

Centralized logging

A common pattern sends logs from many accounts to one log archive account. Organization trails, cross account log delivery and bucket policies make that possible. Central storage also keeps logs away from the people being audited.

What to remember for the exam

  • CloudTrail records API calls. Event history covers 90 days of management events.
  • A trail to S3 is needed for longer retention. Data events must be enabled.
  • Turn on log file integrity validation and protect the log bucket.
  • CloudTrail Lake offers SQL queries over events with configurable retention.
  • CloudWatch Logs needs a retention setting, and subscription filters stream logs onward.
  • Redshift audit logs go to S3 or CloudWatch. User activity logging needs a parameter group setting.
  • Athena over S3 logs with partition projection is the low cost way to analyze large volumes.
  • Send logs to a central, locked down account for audit.
Exam tip

"Who read this object in S3" needs CloudTrail data events or S3 server access logs, since management events do not show object reads.

Common mistakes

Relying on Event history. It keeps only 90 days of management events.

Assuming data events are on. Reads and writes of objects are not logged until you enable them.

Leaving the log bucket open. Anyone who can alter logs can hide their actions.

Keeping logs forever by accident. Log groups default to never expire, which raises cost.

Watch out

Redshift user activity logging is not on by default, so queries may be missing from the audit trail unless you enable the parameter.

Check yourself

  • How long does CloudTrail Event history keep management events?

    90 days.

  • What must you enable to log S3 object reads in CloudTrail?

    Data events for S3.

  • How can you prove that log files were not altered?

    Enable log file integrity validation and check the digest files.

Topic 6 of 7 in Data Security and Governance

Test yourself on Data Security and Governance

The full AWS DEA-C01 question bank has 845 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.