Sub topic 6
How logs are delivered and organized in S3
This chapter assumes you can read JSON, use the AWS CLI, and know what an S3 bucket, prefix, and bucket policy are. It also assumes you have created a trail as in the previous chapter. Here you will see where a trail writes its files, how the files are named, and what goes wrong when delivery fails.
The delivery path
A trail batches events and writes them to S3 as compressed files. Delivery is not instant. CloudTrail typically delivers log files about 5 minutes after the API call, so a call made a minute ago may not be in S3 yet. Event history shows it sooner.
The object key layout
Every log file lands under a predictable key. For a single-account trail it looks like this:
AWSLogs/123456789012/CloudTrail/us-east-1/2026/11/20/123456789012_CloudTrail_us-east-1_20261120T0915Z_AbC123xYz.json.gzThe parts are:
AWSLogs/is the fixed top-level prefix. If you set a prefix on the trail, it goes in front of this.123456789012is the account ID. An organization trail adds the organization ID (o-...) before the account ID.CloudTrail/separates log files from digest files, which useCloudTrail-Digest/.us-east-1is the Region where the event happened. A multi-Region trail writes one folder per Region into the same bucket.2026/11/20is the UTC date.- The file name ends with a UTC timestamp and a random string. It has a
.json.gzextension.
This layout lets you narrow a search by account, Region, and day with a prefix alone. Athena partition projection and S3 lifecycle rules rely on the same structure.
Bucket policy requirements
CloudTrail writes as the service principal cloudtrail.amazonaws.com, so the bucket policy must allow it. It needs s3:GetBucketAcl on the bucket and s3:PutObject on the AWSLogs/ path. Scoping the policy to your trail's ARN with aws:SourceArn prevents other accounts' trails from writing into your bucket.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSCloudTrailAclCheck",
"Effect": "Allow",
"Principal": { "Service": "cloudtrail.amazonaws.com" },
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::my-cloudtrail-logs-bucket",
"Condition": {
"StringEquals": {
"aws:SourceArn": "arn:aws:cloudtrail:us-east-1:123456789012:trail/org-audit-trail"
}
}
},
{
"Sid": "AWSCloudTrailWrite",
"Effect": "Allow",
"Principal": { "Service": "cloudtrail.amazonaws.com" },
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::my-cloudtrail-logs-bucket/AWSLogs/123456789012/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control",
"aws:SourceArn": "arn:aws:cloudtrail:us-east-1:123456789012:trail/org-audit-trail"
}
}
}
]
}If the policy is missing or wrong, create-trail fails with InsufficientS3BucketPolicyException. If someone edits the policy later, the trail stays configured but delivery fails silently from your point of view. Check the trail's status after any policy change:
aws cloudtrail get-trail-status --name org-audit-trailLook at LatestDeliveryTime and LatestDeliveryError. A stale delivery time or a non-empty error means the files are not arriving.
Inspecting a delivered file
List a day's files with a prefix, then download one and decompress it. Each file holds a single JSON object with a Records array.
aws s3 ls s3://my-cloudtrail-logs-bucket/AWSLogs/123456789012/CloudTrail/us-east-1/2026/11/20/
aws s3 cp s3://my-cloudtrail-logs-bucket/AWSLogs/123456789012/CloudTrail/us-east-1/2026/11/20/<file-name>.json.gz - \
| gunzip \
| jq '.Records[] | {eventTime, eventName, user: .userIdentity.arn}'Replace <file-name> with a real key from the listing.
Common surprises
- Events appear out of order. A file covers a delivery window, and records inside it are not guaranteed to be sorted by
eventTime. Sort after you load them. - A day folder is missing. CloudTrail writes only when it has events for that Region and window, so a quiet Region may have no folder.
- Files are encrypted. By default, CloudTrail files use S3-managed encryption (SSE-S3). With a KMS key, readers also need
kms:Decryptpermission, oraws s3 cpreturns access denied even though S3 permissions are correct. - Digest files live elsewhere. Digest files sit under
CloudTrail-Digest/, so a prefix search underCloudTrail/never returns them.
Exercise
You want only the events that happened in eu-west-1 on 2026-11-20 for account 123456789012, from a trail with no custom prefix. Which S3 prefix do you list, and why might a trail status check show no new files even though the trail is logging?
Show answer
List AWSLogs/123456789012/CloudTrail/eu-west-1/2026/11/20/. If get-trail-status shows an old LatestDeliveryTime or a LatestDeliveryError, the bucket policy (or KMS permissions) likely blocks delivery. Delivery is also delayed by about 5 minutes, so very recent events may simply not have arrived yet.