Lambda Functions don't send proper error logs to the Given email

Viewed 69

I created this lambda function(lambda1) which will notify me about the errors that occurs in another lambda(Lambda2). here is the code for the lambda1 which will send email notification

console.log("Loading function");
var AWS = require("aws-sdk");

exports.handler = function(event, context) {
    var eventText = JSON.stringify(event, null);
    console.log("Received event:", eventText);
    var sns = new AWS.SNS();
    var params = {
        Message: JSON.stringify(eventText), 
        Subject: "This is Error Notifiation in Lambdas",
        TopicArn: "arn:aws:sns:example/example"
    };
    sns.publish(params,  context.done);
};

the error logs that lambda2 generated are these.

This is a sample DEBUG message..    
This is a sample INFO message.. !!
This is a sample ERROR message...

This above logs will trigger my lambda1 and will send me these logs to my email. But instead sending me the same logs generated by lambda2, lambda1 sent me the following logs, "{\"awslogs\":{\"data\":\"H4sIAAAAAAAAADWQy27CMBBFfyVYXZLGz4mdXaSmbECVSFaFqHKIoZHyQIkpQoh/7wDtaDa+M75Hd66kc9NkD664HB1JyFtapF+rLM/TRUbmZDj3bkSZCS50HANViqHcDofFOJyOOInseYpa21W1jdw4DuPC4Rfrm/6wfKjP9dyPzna4zylnEeMRo9HmZZkWWV6UauekBKiBsr20oCthKlnHxnEtdi6+W0ynatqNzdE3Q//etN6NE0k2ZHV5Pkj5oGQ/rvf3wZU0NcIEKCUMFZwqwYBxg3CtY264VCBAMyk5k0ZoLMW4As2NkjxGoG/wMN52mJGBMEyImBpQcv5/MLTfZOv1x7rc+nuokPGQ0YLRRKmEmldQ4hMnFqgGZ8OK6jrEcCrUGmgo98pUYIACxFtffDdTgG2DCYmtCx7GwR/pFSuYzbY9uZW3X8lHDk6xAQAA\"}} strong text How will I get the same exact logs lambda2 generated?

1 Answers

it looks like you need to decode the text in the event:data field, base64 decoder I think I have used before for something simmular.

This will make you data readable and after that you can determine if you have what you want.

My understanding of your issue: Lambda2 wirte error logs -> CW -> Lambda1 gets trigged by CW -> Lambda1 Select data from event and decode -> Lambda1 sends email.

Related