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

gefragt vor 2 Jahren194 Aufrufe
1 Antwort
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
EXPERTE
beantwortet vor 2 Jahren
profile pictureAWS
EXPERTE
Uri
überprüft vor 2 Jahren
  • I would also look at using Lambda Power Tools, which helps you in writing logs according to the best practices.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen