Is it possible to log the request body size in AWS API Gateway?

Viewed 479

I have an API Gateway -> SQS integration where every request writes the request body as an SQS message. Since the maximum size for SQS messages is 256kb I'd like to have an alert when the request size is larger than this threshold. Is that possible?

I see it's possible to log the response size but not the request.

1 Answers

Api Gateway Logs will show an error message , if we have enable Enable CloudWatch Logs and Log full requests/responses data at Api Gateway Stage.

{
    "Error": {
        "Code": "InvalidParameterValue",
        "Message": "One or more parameters are invalid. Reason: Message must be shorter than 262144 bytes.",
        "Type": "Sender"
    },
    "RequestId": "b410da48-7fee-5c2e-b046-82ed9a872753"
}

Then we can create a cloudwatch metric filter on Message must be shorter to trigger an alert.

Related