CloudFront Functions can now log straight into your access logs!
Hi everyone, it's Shiichan! Today I found an update that CloudFront developers are going to love!
AWS What's NewWhat was announced?
AWS's What's New announced that Amazon CloudFront Functions can now write custom data directly into CloudFront access logs. With the new cf.logCustomData() helper method, you can call it from a viewer request or viewer response function to log whatever values you want straight into the access log record.
The story so far
Until now, CloudFront Functions could only send log data to Amazon CloudWatch Logs, as a separate system from CloudFront access logs. That meant you had to correlate what your function decided with the access log's request record after the fact, across two different systems.
What changes
Just by calling cf.logCustomData(), you can now log things like A/B test variant assignments, authentication outcomes, or routing decisions directly into that request's access log record. It works with both CloudFront real-time log configurations and standard logging (v2), so you can analyze function behavior and request outcomes together with a single query, instead of hopping between systems. Your existing console.log() calls still work too, and you can use both together.
Dive Deep
It's simple to use: just call cf.logCustomData() from a viewer request or viewer response function. This is available today across all CloudFront edge locations.
As for pricing, there's no additional charge for using cf.logCustomData() itself. You just pay the usual CloudFront Functions invocation pricing and access log delivery charges.
Wrap-up
- CloudFront Functions now has
cf.logCustomData()for writing custom data straight into access logs - Previously, logs could only go to CloudWatch Logs, separate from access logs
- You can now see things like A/B test results, auth outcomes, and routing decisions right in the access log
- It works with both real-time log configurations and standard logging (v2), and can be combined with
console.log() - No extra charge, and it's available today across all edge locations
This update is for developers who want to trace request behavior closely in CloudFront Functions!