Log Custom Response Headers from CloudFront

0

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:

  1. Lambda@Edge - Write to CloudWatch or DynamoDB - this can be fairly expensive just due to the number of invocations we're processing
  2. 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.

已提問 1 個月前檢視次數 326 次
2 個答案
0

Why not leverage CloudFront access logs which are delivered to S3 at no additional cost. You can use a logging format like httpd which includes response headers in the logs. Then process the logs to extract the header value as needed.

Remember to place a policy on logs and delete after processing to not incur in archive costs.

profile pictureAWS
已回答 1 個月前
profile picture
專家
已審閱 1 個月前
  • 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?

0

Custom log headers do not seem to be available here. Am I missing something? There are only a fixed set of headers.

已回答 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南