Incident Response · Topic 5 of 5

Investigating Security Events

Investigate AWS security events by correlating CloudTrail, Athena, CloudTrail Lake, Detective, flow logs and Access Analyzer, then fix gaps afterward.

  • 5 min
In a nutshell
  • lookup-events and Event history cover 90 days of management events only. Use Athena or CloudTrail Lake for more history or data events.
  • Detective is the tool for behaviour baselines, timelines and cross account relationships.
  • Flow logs show who talked to whom. Resolver query logs show which names were looked up.

What it is

Investigation answers four questions about an event: what happened, who or what did it, which resources and data were affected, and whether it is over. The answers come from correlating logs and findings, not from any one tool.

Good investigations start narrow, from the indicator you have, and widen: from one key to all its activity, from one instance to the network it talked to.

IndicatorIP, key, findingPivotCloudTrail, flow logsScoperesources and dataTimelinefirst and last activityReportroot cause

How it works

Choose the right data source

QuestionSource
Which API calls did this principal make?CloudTrail, queried by Athena, CloudTrail Lake or lookup-events
Which hosts talked to this IP?VPC Flow Logs
Which domain did this host look up?Route 53 Resolver query logs
Which web requests hit the application?ALB, CloudFront and WAF logs
What is this principal's normal behaviour?Detective
Which resources are shared outside the account?IAM Access Analyzer
Which permissions were actually used?IAM last accessed information and Access Analyzer unused access findings

Querying CloudTrail with Athena

For history beyond 90 days or for data events, query the trail files in S3. An Athena table over the trail location lets you use SQL.

-- Athena: everything one access key did, oldest first
SELECT eventtime, eventsource, eventname, awsregion,
       sourceipaddress, useragent, errorcode
FROM cloudtrail_logs
WHERE useridentity.accesskeyid = 'AKIAIOSFODNN7EXAMPLE'
  AND eventtime > '2026-09-25T00:00:00Z'
ORDER BY eventtime;

Filter on partitions such as the date and Region where your table allows it, because Athena charges by data scanned. Useful pivots are sourceipaddress, useragent (a script user agent from a person who normally uses the console is a clue), errorcode and eventname.

CloudTrail Lake offers the same style of SQL on an event data store without building tables, and it can query events from several accounts when the store is organization wide. CloudWatch Logs Insights is the quick option when the trail also feeds a log group.

Reading the clues

  • A burst of AccessDenied errors from a new IP suggests an attacker probing the permissions of a stolen key.
  • Calls such as GetCallerIdentity, ListBuckets and DescribeInstances early in a session suggest reconnaissance.
  • StopLogging, DeleteTrail or DeleteDetector (GuardDuty) suggest defence evasion.
  • RunInstances in unusual Regions suggests resource abuse such as mining.
  • Console sign in without MFA, or from a new country, suggests a stolen password.

The userIdentity block tells you the principal type, the role session name, and, for assumed roles, the original identity through the session context. Follow an assumed role session back to the person or system that assumed it.

Using Detective

Detective builds a behaviour graph from CloudTrail, flow logs, GuardDuty and other sources. From a finding, you can open the principal and see its API call volume over time, new geographies and the resources it touched compared with its baseline. This is faster than writing queries when you need a timeline across accounts.

Network investigation

Flow logs give source, destination, port, bytes and the accept or reject action. Find the compromised host, list its outbound destinations, and look for unusual ports or large transfers to a single address. Match any suspect domain against Resolver query logs, since DNS often reveals command and control traffic that has no distinct port.

For packet level proof, Traffic Mirroring can copy traffic from a network interface to an analysis tool, but it must be enabled before the traffic occurs.

Post incident work

Close the loop. Record the timeline, root cause, impact and time to detect, contain and recover. Then change something durable.

  • Add a detection for the gap, such as an alarm or a GuardDuty response rule.
  • Remove the permission or exposure that allowed the incident, perhaps with a permission boundary or an SCP.
  • Update the runbook and run the scenario again as a test.
  • If regulations apply, notify the right parties within the required period.
IncidentclosedlessonsDetectionnew rulePreventionSCP or policy fixRunbookupdated and tested

What to remember for the exam

  • lookup-events and Event history cover 90 days of management events only. Use Athena or CloudTrail Lake for more history or data events.
  • Detective is the tool for behaviour baselines, timelines and cross account relationships.
  • Flow logs show who talked to whom. Resolver query logs show which names were looked up.
  • Access Analyzer shows resources shared outside your zone of trust, and unused access findings show permissions that were not used.
  • Follow assumed roles back through the userIdentity session context to find the original actor.
  • Defence evasion events such as StopLogging deserve immediate attention.
  • Traffic Mirroring must be configured before an incident to capture packets.
  • Finish with lessons learned: new detections, tighter permissions and tested runbooks.
Exam tip

For "which user made this change, and from where", the answer is CloudTrail, and for "what else did that principal do compared with normal", the answer is Detective.

Common mistakes

Searching only recent history. An incident may have started weeks ago, so check the full trail in S3.

Trusting the role name alone. Many people can assume the same role, so read the session name and the source identity.

Looking only at denied calls. Successful calls show what the attacker actually did.

Skipping the report. Without lessons learned, the same gap stays open.

Watch out

Querying logs in the same account that the attacker controls can be misleading, so use the copy in the central log archive account.

Check yourself

  • Where do you query CloudTrail events older than 90 days?

    In the trail files in S3 with Athena, or in a CloudTrail Lake event data store.

  • Which service shows a principal's behaviour compared with its baseline?

    Amazon Detective, using its behaviour graph.

  • Why follow the session context in userIdentity?

    It shows who or what originally assumed the role, which identifies the real actor.

Topic 5 of 5 in Incident Response

Test yourself on Incident Response

The full AWS SCS-C03 question bank has 858 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.