Auditing with CloudTrail and AWS Config

Record every API call with CloudTrail, track configuration history and compliance with AWS Config, and investigate who changed what.

Intermediate · about 3 hours · difficulty 2/5

Learn first: CloudWatch Metrics, Logs and Alarms, Multi-Account Strategy with AWS Organizations

When a security group is opened to the world at 2 am, you need to know who did it, from where and when. That is what auditing services are for.

AWS CloudTrail

  • Records management events (API calls like RunInstances, PutBucketPolicy, CreateUser) in every account, including console clicks.
  • Event history shows the last 90 days for free.
  • Create an organization trail that delivers logs from all accounts and regions to a central, locked-down S3 bucket in a log archive account.
  • Data events (S3 object reads, Lambda invokes) cost extra; enable them selectively for sensitive buckets.
  • CloudTrail Lake or Athena lets you query trails with SQL.

AWS Config

  • Records the configuration history of resources: what a security group looked like last Tuesday.
  • Config rules (managed or custom) check compliance continuously: S3 buckets must block public access, EBS volumes must be encrypted, root must have MFA.
  • Conformance packs bundle rules for frameworks like CIS benchmarks.
  • Remediation can fix non-compliant resources automatically through SSM documents.

Azure Activity Log with Azure Policy, and Google Cloud Audit Logs with Security Command Center cover similar ground.

Pitfalls

  • No multi-region trail, so activity in unused regions (often where attackers launch miners) goes unseen.
  • Trail logs stored in a bucket that the same admins can delete.
  • Turning on every Config rule in every region and paying for evaluations nobody reads.

You are ready to move on when you can find, in CloudTrail, who modified a specific security group and show its previous configuration in Config.

Key concepts

  • Management vs data events
  • Event history
  • Organization trails
  • Log file integrity validation
  • AWS Config recorder
  • Config rules and conformance packs
  • Querying trails with Athena or CloudTrail Lake

Mini project

Create a multi-region trail delivering to an S3 bucket, open and close port 22 on a security group, then find both events in CloudTrail and write the who, what, when and source IP. Enable one Config rule (s3-bucket-public-read-prohibited) for an hour. Delete the Config recorder afterwards because evaluations are billed.

Check yourself

Which service answers 'who deleted this bucket?', and which answers 'what did this security group look like last week?'

Free resources