We have a CloudFront distribution where we'd like to log the value of a custom response header for later consumption. This is helping with billing of our API. Not all requests hit the origin, and cost varies depending on the type/data returned in the response. What is most cost effective way to achieve this? I have stumbled across a few:
- Lambda@Edge - Write to CloudWatch or DynamoDB - this can be fairly expensive just due to the number of invocations we're processing
- CloudFront Functions - Log to CloudWatch itself, but that seems unreliable, due to this clause on the docs page:
We recommend that you use the logs to understand the nature of the requests for your content, not as a complete accounting of all requests. CloudFront delivers edge function logs on a best-effort basis. The log entry for a particular request might be delivered long after the request was actually processed and, in rare cases, a log entry might not be delivered at all. When a log entry is omitted from edge function logs, the number of entries in the edge function logs won't match the usage that appears in the AWS billing and usage reports.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions-logs.html
Is there a better way to do this? Customize the the list of response headers that are saved in the log would be the easiest.
Oh wonderful, custom log formats and headers are available there? I hadn't seen that before. I'll give that a try. Thank you very much.
EDIT: I'm not seeing where to set that in the console or in the docs...
EDIT 2: Are these only available on Real-Time logs?