AWS CloudTrail, AWS Config and AWS X-Ray: Audit, Configuration History and Distributed Tracing

AWS SysOps Associate 55 min min read Updated: Nov 17, 2026 Intermediate
AWS CloudTrail, AWS Config and AWS X-Ray: Audit, Configuration History and Distributed Tracing
Intermediate Topic 4 of 4

Three Questions, Three Services

QuestionService
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 typeExamplesDefault
ManagementCreate/delete resources, IAM changes, console login, security group changesLogged in event history and trails (read and write selectable)
DataS3 object-level (GetObject, PutObject), Lambda Invoke, DynamoDB item accessOff by default, extra cost. Enable for sensitive buckets
Network activityVPC endpoint API callsOptional
InsightsDetects unusual API call rate or error rateOptional, 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
  • errorCode of AccessDenied helps debug IAM permission issues
  • EventBridge on CloudTrail events (detail-type: AWS API Call via CloudTrail) gives near real-time alerts, such as root login or StopLogging

AWS Config

ConceptMeaning
Configuration recorderRecords resource configurations and changes per Region (all or selected types)
Configuration item (CI)Snapshot of a resource: attributes, relationships, related events
Configuration history / timelineSee how a resource changed over time and what changed
Delivery channelS3 bucket for history and snapshots, optional SNS
Config rulesEvaluate 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 triggersConfiguration changes or periodic
ComplianceCOMPLIANT, NON_COMPLIANT, NOT_APPLICABLE, INSUFFICIENT_DATA
RemediationAttach an SSM Automation document to fix non-compliance (manual or automatic)
AggregatorSingle view across accounts and Regions (organization aggregator)
Conformance packsBundles of rules and remediations deployed as a unit (for example CIS, PCI templates)
Advanced queriesSQL-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:PutTraceSegments and PutTelemetryRecords
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-RayMeaning
Orange / red node on the service mapClient errors (4xx) / faults (5xx)
Long subsegment to DynamoDB or RDSSlow dependency
Many downstream calls in one traceN+1 pattern
Gaps between segmentsQueueing, cold start or missing instrumentation

Putting Observability Together

ToolRole in an incident
CloudWatch alarmDetects the symptom
CloudWatch dashboard / Logs InsightsShows scope and error details
X-Ray / Application SignalsFinds the slow or failing component
Config timelineShows what changed in configuration
CloudTrailShows who made the change
SSM Automation / runbookFixes it

Practice Tasks

  1. Create a multi-Region organization trail with validation and an Athena table
  2. Find who deleted a security group using CloudTrail
  3. Enable AWS Config with the restricted-ssh rule and auto-remediation
  4. Read the Config timeline of a resource after a change
  5. 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.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators