27-08-2022, 10:49 AM
(26-08-2022, 01:51 PM)Jyotheesh_K Wrote: I have created a Rest APIGW and created a log group in Cloud Watch and configured a logs in log format.
Now, making a get call to APIGW. In headers I am sending TransactionID. How to capture this header in Logs. Please find below attached screenshot.
I am able to capture rest of the logs. Is there any context variable to extract headers in log format?
From what I know, the standard API logs wont capture custom header variables. As shown on this link, only a set of predefined headers or other context variables are available for logging in the standard API logs. To actually get the header, you have a couple of options.
1. If you have already enabled custom logging to cloudwatch, make sure the "Log the full request/response data" is checked in the API Stage Log/Trace. Warning: This will generate over 20-40 lines of logs for each request, so consider your logging cost when enabling this.
2. Use lambda proxy-intergration to pass this header variable to lambda to then log it into cloudwatch, which can be achieved by using custom request body mapping templates in API GW.
I would also recommend reading this blog post for a more detailed explanation.