AWS Discussion Forum
AWS CLOUDWATCH LOGS_$context.requestOverride.header.* - Printable Version

+- AWS Discussion Forum (https://letstalkaws.com)
+-- Forum: Q & A (https://letstalkaws.com/forum-10.html)
+--- Forum: Developer Help (https://letstalkaws.com/forum-24.html)
+--- Thread: AWS CLOUDWATCH LOGS_$context.requestOverride.header.* (/thread-75.html)



AWS CLOUDWATCH LOGS_$context.requestOverride.header.* - Jyotheesh_K - 24-08-2022

Trying to fetch header values from request using Access logging Variables($context.requestOverride.header.*) provided by AWS for an API Gateway. This Particular value is not Logging in CloudWatch.Please find attached document.

Please let me know if I need to do anything further.


Thanks & Regards
Jyotheesh K


RE: AWS CLOUDWATCH LOGS_$context.requestOverride.header.* - fzs - 24-08-2022

(24-08-2022, 10:33 AM)Jyotheesh_K Wrote: Trying to fetch header values from request using Access logging Variables($context.requestOverride.header.*) provided by AWS for an API Gateway. This Particular value is not Logging in CloudWatch.Please find attached document.

Is the requestOverride context variable actually setup in the body mapping templates for API GW? As in are you actually seeing this come through in the request/response but just not logging to CW?

Also, better to attach the screenshots directly in your post than adding as a document. The forum supports inline images.


RE: AWS CLOUDWATCH LOGS_$context.requestOverride.header.* - Jyotheesh_K - 26-08-2022

Hi,
Thanks for your response. 
To be more clear on this, I have two queries

1.We have TransactionID header coming in the request and it needs to be logged in cloud watch. Could you please guide me to achieve this use case.

2.We have a requirement to capture the time taken by APIGW for the transaction. could you please assist me in achieving this use case.


Regards,
Jyotheesh K


RE: AWS CLOUDWATCH LOGS_$context.requestOverride.header.* - fzs - 26-08-2022

(26-08-2022, 07:41 AM)Jyotheesh_K Wrote: 1.We have TransactionID header coming in the request and it needs to be logged in cloud watch. Could you please guide me to achieve this use case.

2.We have a requirement to capture the time taken by APIGW for the transaction. could you please assist me in achieving this use case.

As mentioned in the forum posting guildelines, you will have to tell us what all has already been setup/tried by you to achieve this as it involves multiple steps including specifying the right $context variables, log formats, log groups etc. Also, without any information on the request template format that is coming through to API GW or whether it's an HTTP or REST request, it's impossible to say how to log it. Please provide the details on what's already setup.

For HTTP requests, there are the variables that can be logged to cloudwatch: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-logging-variables.html


RE: AWS CLOUDWATCH LOGS_$context.requestOverride.header.* - Jyotheesh_K - 26-08-2022

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?


RE: AWS CLOUDWATCH LOGS_$context.requestOverride.header.* - fzs - 27-08-2022

(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.