Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS cloudwatch is truncating logs

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.

like image 954
LP13 Avatar asked Jan 08 '19 18:01

LP13


People also ask

Is there a limit to CloudWatch 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.

How do I find my CloudWatch log size?

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.


2 Answers

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.

like image 108
A.Khan Avatar answered Oct 03 '22 01:10

A.Khan


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/

like image 27
rahulbaisla Avatar answered Oct 03 '22 01:10

rahulbaisla