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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则