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 Antworten
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
beantwortet vor einem Monat
profile picture
EXPERTE
überprüft vor einem Monat
  • 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.

beantwortet vor einem Monat

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen