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

asked 2 years ago189 views
1 Answer
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
EXPERT
answered 2 years ago
profile pictureAWS
EXPERT
Uri
reviewed 2 years ago
  • I would also look at using Lambda Power Tools, which helps you in writing logs according to the best practices.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions