How to add custom userUUD when logging aws Lambda Function

0

I have a few Lambda functions that run using nodejs. In the function code I have a few logs eg consoleLog('email provided') etc

I can also see the logs in cloud watch.

My question: I it possible to set a userUUID on the function so that I can filter cloud watch logs by uuid or tag or something like that?

The app sends a request to AWS gateway, which calls the lambda. In the request, is the UUID. So wondering if I can use that as some type of filter

Thanks

已提问 2 年前194 查看次数
1 回答
0

The lambda function context has a unique awsRequestId, that you can use to uniquely identify every invocation of a lambda function. By default, lambda generated logs have the Request ID, but you can also get it from the context object and add it to every log statement in your own lambda code - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html

Also take a look at this blog about logging when using Lambda with API Gateway - https://aws.amazon.com/blogs/compute/techniques-and-tools-for-better-serverless-api-logging-with-amazon-api-gateway-and-aws-lambda/

profile pictureAWS
专家
已回答 2 年前
profile pictureAWS
专家
Uri
已审核 2 年前
  • I would also look at using Lambda Power Tools, which helps you in writing logs according to the best practices.

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

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

回答问题的准则