1

I have this basic lambda that posts an image to a web server. From the events in CloudWatch, I can log successfully anything that happens in that lambda function :

enter image description here

From this Log Group (the lambda function) I clicked on Stream to AWS Lambda, chose a new lambda function in which I expect to receive my logs and didn't put any filters at all so I can get all logs.

The Lambda is triggered properly, but the thing is when I persist what I received in the event and context objects, I have all CloudWatch log stream information but I don't see any of the logs.

What I get :

enter image description here

Do I need to specify a filter for me to see any logs at all? Because in the filter section if I don't put any filters and click on test filter, I get all the logs in the preview window which seems to mean it should send the whole logs to my Lambda function. Also, it looked to me the logs where that unreadable stream in AWSLogs and that it was in Base64 but didn't get any results trying to convert that.

3
  • 1
    The logs are gzipped and then base64-encoded. You need to reverse both in your code.
    – jarmod
    Commented Sep 14, 2018 at 13:03
  • @jarmod Thanks that was exactly it. FYI I took a look at another anwser you gave on the subject and tried your code snippet but got a JSON parsing error. stackoverflow.com/a/52197455/1063093 but the decryption works fine thanks !
    – phadaphunk
    Commented Sep 14, 2018 at 13:21
  • 1
    FYI I removed the ascii decoding from that other answer because it was unnecessary and could cause JSON parsing problems.
    – jarmod
    Commented Sep 14, 2018 at 13:31

1 Answer 1

4

Yes the logs are gzipped and base64-encoded as mentioned by jarmod.

Sample code in NodeJs for extracting the same in lambda will be:

var zlib = require('zlib');
exports.handler = (input, context, callback) => {
    var payload = new Buffer(input.awslogs.data, 'base64');
    zlib.gunzip(payload, function(e, result) {
        if (e) { 
            context.fail(e);
        } else {
            result = JSON.parse(result.toString());
            console.log(result);
        }
    });
1
  • Works great. Thanks guys !
    – phadaphunk
    Commented Sep 14, 2018 at 13:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.