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

feita há 2 anos194 visualizações
1 Resposta
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
ESPECIALISTA
respondido há 2 anos
profile pictureAWS
ESPECIALISTA
Uri
avaliado há 2 anos
  • I would also look at using Lambda Power Tools, which helps you in writing logs according to the best practices.

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas