How to save response and request body from api gateway to s3?

0

I have an Api Gateway with different integrations: lambda proxy, sagemaker, and elastic load balancer. What I want is to automatically catch request body, and response body, and send them to s3. My first approach was to configure a custom access logging to the methods I want and send to s3 through kinesis firehose; however with this approach the only information accessible were $context variables, and I need the request body and response body for auditing and monitoring purposes. My second approach was to enable Full request and response logs, create a subscription filter and send response body and request to s3 through kinesis firehose, this would work; however due to Api Gateway limits, if response and request body length surpass 1024 bytes, they will be truncated by API Gateway before submission to CloudWatch Logs.

Is there is another way to accomplish this task ? or is simply not possible to catch every request and response information directly from Api Gateway and the only way is to implement another service that receive the information from each one of my integrations and send it to s3?

1 個回答
1

Hi,

I don't think so. As you mention, API Gateway limits log events to 1024 bytes and greater events are truncated before submission to CloudWatch logs, so, either you centralize it in a proxy (Cost and latency must be considered), or you implement it in the service itself.

On the other hand, I recommend you be careful with full request and response logs on production APIs, since could contain sensitive data.

profile picture
專家
已回答 8 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南