AWS CloudTrail, AWS Config and AWS X-Ray: Audit, Configuration History and Distributed Tracing
Three Questions, Three Services
| Question | Service |
|---|---|
| Who called which API, from where, and when? | CloudTrail |
| What did the resource look like before and after, and is it compliant? | AWS Config |
| Where is the time spent in a request across services? | X-Ray |
| Is it healthy right now? | CloudWatch |
AWS CloudTrail
- Records API calls and console actions as events:
eventTime,eventName,eventSource,userIdentity,sourceIPAddress,requestParameters,errorCode - Event history: last 90 days of management events per Region, free, searchable in the console
- Trail: continuous delivery to S3 (and optionally CloudWatch Logs and EventBridge). Create an organization trail and a multi-Region trail so nothing is missed
- Turn on log file integrity validation (digest files with hashes) to prove logs were not altered
- Protect the bucket: separate log archive account, bucket policy, MFA delete or Object Lock, KMS encryption
| Event type | Examples | Default |
|---|---|---|
| Management | Create/delete resources, IAM changes, console login, security group changes | Logged in event history and trails (read and write selectable) |
| Data | S3 object-level (GetObject, PutObject), Lambda Invoke, DynamoDB item access | Off by default, extra cost. Enable for sensitive buckets |
| Network activity | VPC endpoint API calls | Optional |
| Insights | Detects unusual API call rate or error rate | Optional, extra cost |
bash
aws cloudtrail create-trail --name org-trail --s3-bucket-name audit-logs-111111111111 --is-multi-region-trail --is-organization-trail --enable-log-file-validation
aws cloudtrail start-logging --name org-trail
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=DeleteSecurityGroup --max-results 5
aws cloudtrail validate-logs --trail-arn $TRAIL_ARN --start-time 2026-11-01T00:00:00Z
Investigating With CloudTrail
sql
-- Athena or CloudTrail Lake: who terminated instances this week?
SELECT eventtime, useridentity.arn, sourceipaddress, requestparameters
FROM cloudtrail_logs
WHERE eventname = 'TerminateInstances' AND eventtime > '2026-11-10'
ORDER BY eventtime DESC;
-- Failed or denied calls
SELECT eventname, errorcode, count(*) c FROM cloudtrail_logs
WHERE errorcode IN ('AccessDenied','UnauthorizedOperation') GROUP BY 1,2 ORDER BY c DESC;
- CloudTrail Lake: managed event data store with SQL queries, no Athena setup, retention up to years
- Use Athena over trail files in S3 for flexible analysis (partition by date)
- Typical findings:
userIdentity.type=Root,AssumedRole,IAMUser,AWSService. Find who and the role session errorCodeofAccessDeniedhelps debug IAM permission issues- EventBridge on CloudTrail events (
detail-type: AWS API Call via CloudTrail) gives near real-time alerts, such as root login orStopLogging
AWS Config
| Concept | Meaning |
|---|---|
| Configuration recorder | Records resource configurations and changes per Region (all or selected types) |
| Configuration item (CI) | Snapshot of a resource: attributes, relationships, related events |
| Configuration history / timeline | See how a resource changed over time and what changed |
| Delivery channel | S3 bucket for history and snapshots, optional SNS |
| Config rules | Evaluate resources: AWS managed rules (for example s3-bucket-public-read-prohibited, encrypted-volumes, restricted-ssh, required-tags), custom rules (Lambda or Guard policy-as-code) |
| Evaluation triggers | Configuration changes or periodic |
| Compliance | COMPLIANT, NON_COMPLIANT, NOT_APPLICABLE, INSUFFICIENT_DATA |
| Remediation | Attach an SSM Automation document to fix non-compliance (manual or automatic) |
| Aggregator | Single view across accounts and Regions (organization aggregator) |
| Conformance packs | Bundles of rules and remediations deployed as a unit (for example CIS, PCI templates) |
| Advanced queries | SQL-like queries on current configuration state |
bash
aws configservice describe-configuration-recorders
aws configservice put-config-rule --config-rule '{"ConfigRuleName":"restricted-ssh","Source":{"Owner":"AWS","SourceIdentifier":"INCOMING_SSH_DISABLED"}}'
aws configservice get-compliance-details-by-config-rule --config-rule-name restricted-ssh --compliance-types NON_COMPLIANT
aws configservice get-resource-config-history --resource-type AWS::EC2::SecurityGroup --resource-id sg-0abc --limit 5
aws configservice select-resource-config --expression "SELECT resourceId, configuration.instanceType WHERE resourceType = 'AWS::EC2::Instance' AND configuration.instanceType = 't2.micro'"
- Config records, it does not block changes. Use SCPs or IAM to prevent, Config to detect and fix
- Config costs per configuration item and per rule evaluation, so record only needed resource types in big environments
- CloudTrail answers who, Config answers what and compliance. Use both together during an investigation: Config timeline → find the change time → CloudTrail for the actor
AWS X-Ray
- Traces a request through services, showing latency per segment and errors. Trace = whole request, segment = work in one service, subsegment = downstream call or code section
- Service map visualizes dependencies with latency and error/fault/throttle rates
- Sampling rules control cost (default: first request per second plus 5 percent)
- Annotations (indexed, searchable) and metadata (not indexed) add context
- Instrument with the AWS Distro for OpenTelemetry or X-Ray SDK. For Lambda enable active tracing. For EC2/ECS run the X-Ray daemon or the CloudWatch agent. API Gateway and ALB can add trace headers (
X-Amzn-Trace-Id) - Needs IAM permission
xray:PutTraceSegmentsandPutTelemetryRecords
bash
aws lambda update-function-configuration --function-name checkout --tracing-config Mode=Active
aws xray get-service-graph --start-time $(date -d '-1 hour' +%s) --end-time $(date +%s) --query 'Services[].[Name,SummaryStatistics.ErrorStatistics.TotalCount]'
aws xray get-trace-summaries --start-time $(date -d '-1 hour' +%s) --end-time $(date +%s) --filter-expression 'responsetime > 2 AND service("checkout")'
| Finding in X-Ray | Meaning |
|---|---|
| Orange / red node on the service map | Client errors (4xx) / faults (5xx) |
| Long subsegment to DynamoDB or RDS | Slow dependency |
| Many downstream calls in one trace | N+1 pattern |
| Gaps between segments | Queueing, cold start or missing instrumentation |
Putting Observability Together
| Tool | Role in an incident |
|---|---|
| CloudWatch alarm | Detects the symptom |
| CloudWatch dashboard / Logs Insights | Shows scope and error details |
| X-Ray / Application Signals | Finds the slow or failing component |
| Config timeline | Shows what changed in configuration |
| CloudTrail | Shows who made the change |
| SSM Automation / runbook | Fixes it |
Practice Tasks
- Create a multi-Region organization trail with validation and an Athena table
- Find who deleted a security group using CloudTrail
- Enable AWS Config with the
restricted-sshrule and auto-remediation - Read the Config timeline of a resource after a change
- Enable X-Ray on a Lambda and API Gateway and read the service map
Conclusion
CloudTrail records who did what (keep an organization, multi-Region trail with validation and data events where needed), Config records what changed and checks compliance with rules and remediation, and X-Ray traces slow or failing requests across services. Use the three together to investigate incidents.
Quick Summary: who/what/where; CloudTrail; investigation; Config; X-Ray; putting together.

