Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

897
Vistas
How to log raw JSON to Cloudwatch from AWS Lambda in node.js?

I have some node.js based Lambdas that are logging data.

In order to properly query and filter the data etc, I want to log as pure JSON data from my Lambdas.

However, when I do a regular console.log it makes an ordinary string of the data.

console.log({a:1,b:2,x:"xxx"})

Results in this:

2020-04-29T14:46:45.722Z    3f64c499-fbae-4a84-996c-5e5f0cb5302c    INFO    { a: 1, b: 2, x: 'xxx' }

The logged line above does not seem to be searchable as JSON using the various filter matching options in CloudWatch.

I've tried to call the AWS.CloudWatchLogs API directly but since I'm using lambda I cannot maintain a token between invocations of the functions, so I'm not sure that's the way to go.

Have anyone else had success in logging raw JSON from a Javascript Lambda?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The problem is that console.log() does not go directly to stdout/stderr. You can see that using this Lambda:

const process = require('process');

exports.handler = async (event) => {
    console.log("message 1");
    process.stdout.write("message 2\n");
};

If you invoke that, you will see output like this:

START RequestId: 6942bebc-1997-42cd-90c2-d76b44c637283 Version: $LATEST
2020-04-29T17:06:07.303Z    6935bebc-1d97-42cd-90c2-d76b4a637683    INFO    message 1
message 2
END RequestId: 6942bebc-1997-42cd-90c2-d76b44c637283

So to get the output you want you could either redefine console.log to go to stderr, or write to stdout/stderr directly.

Or you could use a logging framework that writes to stdout/stderr, which may give you more flexibility on how your messages are written. I don't do Node development, but I've heard that Winston is the standard logging framework.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda