Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I log lambda request id into AWS CloudWatch Api gateway log group with JSON format?

I have been working on a REST API which uses AWS API Gateway and lambda function. Both Api gateway and lambda services are logging to CloudWatch service. I need to log lambda request id into AWS CloudWatch API gateway log group. (API-Gateway-Execution-Logs_{api_id}/{staging}).

I manage to get the lambda request id in text format but I want to log it in JSON format. In API gateway logs it is labeled as "AWS Integration Endpoint RequestId". I have tried to find this property from the following link: List of Log Variables

Currently, "$context.requestId" is added into my CloudWatch logs. This is the request id for API Gateway. I need lambda request id in API Gateway logs. I have tried to log "$context.authorizer.principalId" but it is empty.

How can I get lambda request id from context object of API gateway request?

like image 434
Nil Avatar asked Oct 25 '25 00:10

Nil


1 Answers

From the APIG reference, it seems that you can use the $context.awsEndpointRequestId placeholder

like image 65
cgledezma Avatar answered Oct 26 '25 15:10

cgledezma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!