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. 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 ! 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. 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);
        }
    });
Sign up to request clarification or add additional context in comments.

1 Comment

Works great. Thanks guys !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.