Sub topic 14
Investigating with Amazon Detective
This chapter assumes you can read a GuardDuty finding (type, severity, resource, actor), you know what CloudTrail, VPC Flow Logs, and DNS logs record, and you have used the AWS CLI. Earlier chapters showed how a finding is produced and routed. This chapter covers what to do when a finding is not enough on its own to decide whether something bad happened.
What Detective adds to a finding
A GuardDuty finding tells you that something looks suspicious. It does not tell you how the resource behaved before the finding, what else the same principal did, or whether other resources talked to the same remote address. Answering those questions by hand means querying CloudTrail, VPC Flow Logs, and other sources one at a time.
Amazon Detective is a service that does this correlation for you. It ingests log data from your accounts, builds a behavior graph (a linked model of entities such as IAM principals, EC2 instances, IP addresses, and the relationships between them), and presents it as time-based views you can browse in the console.
Detective is an investigation tool. It does not generate threat findings of its own, and it does not block or remediate anything. Use it after a detection service has raised a question.
| Service | Main question it answers | Output |
|---|---|---|
| GuardDuty | Is something suspicious happening? | Findings |
| Security Hub | What is the overall findings and compliance picture? | Aggregated findings and control results |
| Detective | What happened around this finding, and how far did it go? | Graphs, timelines, and investigation reports |
Data sources and the behavior graph
When you enable Detective in an account, it starts ingesting data automatically. You do not configure log delivery yourself.
- AWS CloudTrail management events show which principal called which API, from where, and with what result.
- VPC Flow Logs show network connections to and from your network interfaces.
- GuardDuty findings give Detective the detections that it links to the entities involved.
- Optional sources, such as EKS audit logs, can be added as data source packages if you use those services.
Detective reads these streams independently. You do not need to have VPC Flow Logs turned on in your own account for Detective to use flow data.
The collected data is organized in a behavior graph. A behavior graph is a per-Region container that holds the entities and relationships Detective has observed. Each behavior graph has one administrator account and can include many member accounts. Detective keeps up to a year of history, so a view can show whether today's activity differs from the last several weeks.
Enabling Detective
Detective needs GuardDuty, or a similar detection source, to be useful, and a new account is only worth enabling once GuardDuty has been running. Detective also needs a short period of data collection before its baselines mean much. Enable it early, not during an incident.
The following command creates a behavior graph in the current Region and makes the calling account its administrator.
aws detective create-graphThe response contains a GraphArn. You need it for every other Detective API call.
GRAPH_ARN=$(aws detective list-graphs --query 'GraphList[0].Arn' --output text)
echo "$GRAPH_ARN"Detective is Regional. If you run workloads in several Regions, you create one behavior graph per Region, in the same way you did for GuardDuty detectors.
Multi-account setup
In an AWS Organization, designate a delegated administrator for Detective, as you did for GuardDuty and Security Hub. The management account runs the command, naming the account that will manage the graph.
aws detective enable-organization-admin-account --account-id 111122223333From the delegated administrator, enable member accounts automatically so that new accounts join the graph.
aws detective update-organization-configuration --graph-arn "$GRAPH_ARN" --auto-enablePooling accounts in one graph is what makes cross-account investigations possible. If an access key from account A is used to act in account B, a single graph can show both halves of the story.
Pivoting from a GuardDuty finding
You can reach Detective directly from a GuardDuty or Security Hub finding in the console. The finding's detail pane includes an option to investigate in Detective, which opens a profile for the entity involved, with the finding's time window already selected.
An entity profile is a page for one entity, such as an IAM user, an assumed role session, an EC2 instance, or an IP address. Profiles contain panels, and the useful ones differ by entity type.
| Entity | Panels worth checking first | What you are looking for |
|---|---|---|
| IAM role or user | API call volume, new geolocations, new user agents, failed calls | A principal doing things it has never done |
| EC2 instance | Flow volume to and from remote IPs, related findings | Unusual destinations or data volume |
| IP address | Which accounts and resources it contacted, which principals used it | Whether one remote address touched many resources |
| Access key | Which role sessions and APIs used it | Where a leaked credential was used |
Detective also groups related findings. Finding groups are sets of findings that likely belong to the same activity, such as an initial credential compromise followed by data discovery calls. Reviewing the group is faster than treating each finding as a separate ticket.
A worked investigation
Suppose GuardDuty raises UnauthorizedAccess:IAMUser/InstanceCredentialExfiltration.OutsideAWS. The finding says credentials from an EC2 instance role were used from an IP address outside AWS. Your questions are as follows.
- Is the use outside AWS legitimate, for example a developer using a role from an office network?
- What did the credentials do?
- Did the activity reach other resources or accounts?
Work through these with Detective.
- Open the role session from the finding and set the scope time to the finding window.
- Check the geolocation panel. If the role has only ever called APIs from AWS addresses and the finding shows a new country, treat this as unusual.
- Check the API call panel. A role that normally reads one S3 bucket and now calls
iam:ListUsers,sts:GetCallerIdentity, ands3:ListBucketsis behaving like an attacker enumerating its permissions. - Pivot to the remote IP address profile. See whether that address also used other roles or accounts in the graph.
- Record what you found, and decide: contain, escalate, or close as benign.
Containment is not part of Detective. Once you decide the credentials are compromised, you act through IAM and EC2. A common step is to attach a deny-all policy to the role, or revoke active sessions, and then isolate the instance. The automation chapters covered how to script that.
Investigation reports and the API
For some finding types, Detective can generate an investigation of an IAM principal, which scores indicators such as impossible travel or flagged IP addresses, and produces a report with a severity. You start one for a given entity and time range.
aws detective start-investigation \
--graph-arn "$GRAPH_ARN" \
--entity-arn arn:aws:iam::111122223333:role/app-instance-role \
--scope-start-time 2026-11-25T00:00:00Z \
--scope-end-time 2026-11-26T00:00:00ZThe command returns an InvestigationId. List and retrieve investigations to read the results.
aws detective list-investigations --graph-arn "$GRAPH_ARN"Because the investigation is an API, you can run it from the same Lambda function that handles high-severity findings. The function from the earlier chapter extracts the instance ID. For an IAM finding, you would extract the principal ARN instead and attach the investigation result to the ticket. Keep this to triage enrichment. A person should still read the result before any destructive action.
Common mistakes
- Enabling Detective after an incident starts. Baselines need data. A new graph has little to compare against, and history before the enable date is not backfilled the way you might expect.
- Forgetting Regions. An investigation in one Region will not show activity that happened through the same credentials in another Region unless that Region has its own graph.
- Wrong time window. Profiles default to a recent window. If the finding is a week old, set the scope time to match, or the panels will look empty.
- Using Detective as an alerting system. It does not notify you. Route alerts with EventBridge, and use Detective after the alert arrives.
- Skipping member enrollment. If an affected account is not a member of the graph, its activity is invisible. Turn on auto-enable for the organization.
Cost and when not to use it
Detective is priced by the volume of data ingested into the behavior graph, per account and Region, with a free trial period when you first enable it. The cost grows with log volume, so a busy account with heavy network traffic costs more than a quiet one. Check the free trial usage estimate in the console before committing. Decide per Region and per account whether the investigation speed justifies the cost.
Detective is a good fit when you have a steady stream of findings that need real triage, when credentials are involved, or when you need to show scope to an auditor. It is a poor fit for low-volume accounts where you can read CloudTrail directly, or when your team already uses a security data lake or SIEM with the same sources.
Exercise
GuardDuty reports a finding about an EC2 instance role used from an unfamiliar IP address. You open the role in Detective and the API call panel shows no activity in the finding window. Name two possible reasons, and say what you would check next.
Show answer
The scope time may not match the finding window, so the panel is looking at the wrong period. Or the activity happened in a different Region with a separate behavior graph, or in an account that is not a member of the graph. Check the scope time first, then confirm the Region and member accounts, and then look at the remote IP address profile to see where else it appeared.
Exercise
Which command creates a Detective behavior graph, and why must you repeat it per Region?
Show answer
aws detective create-graph. A behavior graph is a Regional container, so activity in each Region is recorded only in that Region's graph. To investigate across Regions, you create and populate a graph in each one.