I am trying to include the API Gateway Request Id in my SQS message, so that I can log it in the consuming Lambda for tracing.
My mapping template is as follows:
Action=SendMessage&MessageBody=$util.urlEncode($input.body)&MessageAttribute.1.Name=RequestId&MessageAttribute.1.Value.StringValue=$context.requestId&MessageAttribute.1.Value.DataType=String
When I test this via the API Gateway "Test" tab, I can see the request Id exists as part of the MessageAttributes of my SQS message.
However, when I call the API Gateway endpoint via Postman, the request still goes through API Gateway > SQS > Lambda, but there are no message attributes.
Does anyone know why there could be this difference between the test functionality and calling the endpoint?
I am trying to include the API Gateway Request Id in my SQS message, so that I can log it in the consuming Lambda for tracing.
My mapping template is as follows:
Action=SendMessage&MessageBody=$util.urlEncode($input.body)&MessageAttribute.1.Name=RequestId&MessageAttribute.1.Value.StringValue=$context.requestId&MessageAttribute.1.Value.DataType=String
When I test this via the API Gateway "Test" tab, I can see the request Id exists as part of the MessageAttributes of my SQS message.
However, when I call the API Gateway endpoint via Postman, the request still goes through API Gateway > SQS > Lambda, but there are no message attributes.
Does anyone know why there could be this difference between the test functionality and calling the endpoint?
Share Improve this question asked Feb 4 at 11:41 gweilogweilo 634 bronze badges1 Answer
Reset to default 2If it works in the Test tab but not through Postman, it could be an issue with how API Gateway handles the request when it comes from an external client. Check if Postman isn't stripping headers, cause sometimes required headers get lost.
One more tip, try logging $context.requestId
in API Gateway logs to confirm it's being captured correctly.
If nothing works, maybe adding CloudWatch logging at different points in the flow could help figure out where the attributes are getting lost.