Skip to content

CloudTrail Event Replay

CloudTrail event replay lets you take real AWS audit logs and replay the write operations against a CloudMock instance. This recreates your production resource topology locally — tables, queues, buckets, topics, and more — without manual setup.

  1. Export CloudTrail events from your AWS account
  2. Parse the JSON log file to extract write operations
  3. Convert each event into the correct AWS wire-protocol request (JSON, Query, or REST)
  4. Replay the requests against CloudMock in chronological order

CloudMock handles the protocol conversion automatically. A DynamoDB CreateTable event becomes a JSON-protocol POST with the correct X-Amz-Target header. An SQS CreateQueue becomes a Query-protocol POST with Action=CreateQueue. An S3 CreateBucket becomes a REST PUT /bucket-name.

Export recent events using the AWS CLI:

Terminal window
aws cloudtrail lookup-events \
--start-time 2026-03-01T00:00:00Z \
--end-time 2026-04-01T00:00:00Z \
--output json > trail.json

Or download a CloudTrail log file from S3 if you have a trail configured:

Terminal window
aws s3 cp s3://my-trail-bucket/AWSLogs/123456789012/CloudTrail/us-east-1/2026/04/01/trail.json.gz .
gunzip trail.json.gz

The file must contain a top-level Records array in the standard CloudTrail format.

Start CloudMock, then replay:

Terminal window
# Start CloudMock
npx cloudmock
# Replay CloudTrail events (instant mode)
cloudmock cloudtrail replay --input trail.json --endpoint http://localhost:4566

Output:

Replaying 847 CloudTrail events against http://localhost:4566
CloudTrail Replay Results
Total events: 847
Replayed: 312
Skipped: 535
Succeeded: 308
Failed: 4
Duration: 1.2s

Skipped events are read-only operations (DescribeTable, GetObject, etc.) that do not modify state.

Replay only specific services:

Terminal window
cloudmock cloudtrail replay \
--input trail.json \
--services dynamodb,s3,sqs

By default, events replay as fast as possible (--speed 0). To replay at real-time speed:

Terminal window
cloudmock cloudtrail replay --input trail.json --speed 1.0

Use --speed 2.0 for double speed, or --speed 0.5 for half speed.

Write the replay result to a JSON file:

Terminal window
cloudmock cloudtrail replay --input trail.json --output result.json

You can also replay via the admin API:

Terminal window
curl -X POST http://localhost:4599/api/cloudtrail/replay \
-H "Content-Type: application/json" \
-d @trail.json

The response is a JSON object with total_events, replayed, skipped, succeeded, failed, and errors fields.

Use CloudTrail replay in CI to bootstrap a realistic CloudMock environment before running integration tests:

.github/workflows/test.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: viridian-inc/cloudmock-action@v1
- name: Replay production state
run: cloudmock cloudtrail replay --input fixtures/trail.json --output replay-result.json
- name: Run integration tests
run: npm test
env:
AWS_ENDPOINT_URL: http://localhost:4566

CloudTrail replay supports the following services and their most common write operations:

ServiceExample events
DynamoDBCreateTable, PutItem, UpdateItem, DeleteTable
S3CreateBucket, PutObject, DeleteBucket, DeleteObject
SQSCreateQueue, SendMessage, DeleteQueue
SNSCreateTopic, Subscribe, Publish
IAMCreateRole, CreateUser
KMSCreateKey
LambdaCreateFunction, Invoke
CloudWatch LogsCreateLogGroup
KinesisCreateStream
EC2RunInstances
CloudFormationCreateStack
STSGetCallerIdentity

Unsupported events are silently skipped during replay.