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.

2 Answers
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
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • 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.

answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions