I have created an API using AWS api gateway. Under stages the "Log full requests/responses data" checked and "Enable CloudWatch Logs" is also checked.
When i look at the logs in cloudwatch i see some of the logs are "TRUNCATED". In-fact all of the logs are truncating request and response body
. Is there any way to view the entire request/response.
Since there will be multiple integration points it make sense to see the entire logs.
CloudWatch Logs Insights can discover a maximum of 1000 log event fields in a log group. This quota can't be changed. For more information, see Supported logs and discovered fields. CloudWatch Logs Insights can extract a maximum of 200 log event fields from a JSON log.
Open the Amazon CloudWatch console. In the navigation pane, choose Metrics. For each of your log groups, select the individual IncomingBytes metrics. Then, choose the Graphed metrics tab.
Looks like it's one of the known issues in AWS API Gateway.
API Gateway currently limits log events to 1024 bytes. Log events larger than 1024 bytes, such as request and response bodies, will be truncated by API Gateway before submission to CloudWatch Logs.
API Gateway limits log events to 1024 bytes and cannot be increased. The log events larger than 1024 bytes, such as request and response bodies, will be truncated by API Gateway before submission to CloudWatch Logs.
A workaround can be using Lambda proxy integration with API Gateway.
With Lambda proxy integration, API Gateway passes the request as is to the integrated Lambda function with only exception that the order of the request parameters is not preserved.
This request data includes the request headers, query string parameters, URL path variables, payload, body and request context. As Lambda does not truncate log entry, all headers and query string parameters are logged in Lambda's CloudWatch log and can be seen.
Downside of this approach is that lambda would add to the cost.
Read about API Gateway CloudWatch logs here : https://cloudnamaste.com/api-gateway-cloudwatch-logs/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With