chympara
chympara

Reputation: 21

How do I log event and context information automatically on AWS Lambda function failures?

I am trying to log Lambda function failures in such a way that event and context information is saved so that the event information can, if deemed necessary, later be manually republished to the function's trigger. I do not want to handle this logic in the functions themselves.

What I've tried so far:

Upvotes: 2

Views: 1151

Answers (1)

johni
johni

Reputation: 5568

There is no such setting, if that's what you're looking for.

If you'd like these properties to be logged, you have to print them - only that way they are visible in CloudWatch and whatever service that your logs are piped to (logs can be piped to Elasticsearch for example, from CloudWatch).

However, this can be easily done adding these two lines of code:

exports.handler = (event, context, callback) => {
  console.log(JSON.stringify(event));
  console.log(JSON.stringify(context));

  // your code
};

As a rule of thumb, logs are the only way for describing what your lambda went through at each invocation.

Upvotes: 2

Related Questions