Maintained with ☕️ by
IcePanel logo

Amazon CloudFront Functions now supports logging to CloudFront access logs

Share

Services

You can now write custom data directly into CloudFront access logs using a new helper method available from within CloudFront Functions. CloudFront Functions run lightweight JavaScript at the edge for tasks like URL rewrites, header manipulation, and request routing. Previously, you could only emit log data to Amazon CloudWatch Logs as a separate log file from your CloudFront access logs. With this launch, you no longer need to correlate function decisions with CloudFront access log data across separate logging systems. You can call _cf.logCustomData()_ from viewer request or viewer response functions to log values such as A/B test variant assignments, authentication outcomes, or routing decisions directly into the CloudFront access log record for that request. This works with both CloudFront real time log configurations and standard logging (v2), so you can analyze function behavior and request outcomes in a single query. The existing _console.log()_ functionality remains available and the two methods can be used together in the same function. Amazon CloudFront Functions custom log data is available today in all CloudFront edge locations. There is no additional charge for using _cf.logCustomData()._ Standard CloudFront Functions invocation pricing and access log delivery charges apply. To get started, visit [CloudFront Functions helper methods](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/general-helper-methods.html#log-custom-data-method).