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 réponses
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
répondu il y a un mois
profile picture
EXPERT
vérifié il y a un mois
  • 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.

répondu il y a un mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions