Before you start
- Create the Firehose stream and Lambda function in US East (N. Virginia), us-east-1. CloudFront only delivers standard logs to Firehose streams in that region.
- Your AWS user needs permission to create the Lambda function and Firehose stream and to set up CloudFront log delivery. See AWS’s permissions for Firehose log delivery.
- Creating an API key needs an Owner or Admin by default.
Set it up
1
Create an API key
On the AWS Data Firehose integration page, click New API Key, enter a name and click Create API Key. Copy the key from the dialog. Keys start with
aa_.Any Agent Analytics key works for every log source, so you can reuse one from Website > Agent Analytics > Settings. A new key can take up to a minute to start working.2
Create the Lambda function
In the AWS Lambda console (us-east-1), click Create function and choose Author from scratch:
- Function name:
chatfeatured-cloudfront-log-processor - Runtime: Python 3.12
- Architecture: x86_64
3
Create an S3 bucket for failed batches
In the S3 console, create a bucket in us-east-1, for example
chatfeatured-cloudfront-logs-backup-<your-account-id>. Default settings are fine.4
Create the Firehose stream
In the Amazon Data Firehose console (us-east-1), click Create Firehose stream:
- Source: Direct PUT. Destination: HTTP Endpoint.
- Stream name:
chatfeatured-cloudfront-analytics. - Turn on data transformation and select the Lambda function from step 2.
- HTTP endpoint URL:
https://ingest.chatfeatured.com/v1/logs/aws_data_firehose_cloudfront - Authentication: use an access key, and paste your
aa_key as the Access key. - Content encoding: GZIP.
- Buffer hints: 1 MB and 60 seconds.
- Backup settings: back up failed data only to the bucket from step 3.
- Service role: let the console create a new role.
5
Turn on CloudFront standard logging
- In the CloudFront console, open your distribution and choose the Logging tab.
- Choose Add, then Amazon Data Firehose, and select the stream from step 4.
- Under Additional settings, set Output format to JSON.
- Under Field selection, select at least:
date,time,c-ip,cs-method,cs(Host),cs-uri-stem,cs-uri-query,cs(User-Agent),cs(Referer),sc-status. - Save the delivery.
Check that it works
A browser visit won’t show anything, because ChatFeatured keeps only requests from recognized bots. Request a page with a crawler user agent instead:What gets recorded
ChatFeatured keeps requests from AI crawlers and search engine bots (see what gets counted) and discards everything else. The Lambda function also drops 5xx responses and static files, including.txt and .xml, so robots.txt, llms.txt and sitemap.xml fetches don’t appear. Remove '.txt' and '.xml' from IGNORE_EXT to track them.
AWS bills the log delivery, the Firehose stream, the Lambda invocations and S3 storage.
Troubleshooting
Firehose deliveries fail with 401
Firehose deliveries fail with 401
Missing access key or Invalid access key: the stream’s access key is missing, mistyped, deactivated, deleted, or less than a minute old. Fix the access key on the stream.Records fail in the transformation step
Records fail in the transformation step
Check the Lambda function’s logs in CloudWatch. A
JSONDecodeError means the CloudFront delivery isn’t using standard logging with the JSON output format. A timeout means the function’s timeout is still at 3 seconds.Deliveries succeed but nothing shows in Agent Analytics
Deliveries succeed but nothing shows in Agent Analytics
Check that the field selection includes
cs(User-Agent) and cs-uri-stem, then test with the curl command above rather than a browser visit.Related
- Agent Analytics: reading the data
- CloudFront standard logging (v2) in the AWS docs