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

demandé il y a 2 ans194 vues
1 réponse
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
répondu il y a 2 ans
profile pictureAWS
EXPERT
Uri
vérifié il y a 2 ans
  • I would also look at using Lambda Power Tools, which helps you in writing logs according to the best practices.

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions