rrahul963 February 2016

ungzip the data in nodejs

I am trying to ungzip the base64 decoded buffer object using the code below, but the callback function is not getting executed. Can someone tell me what i am missing here

function (event, context) {
    event.Records.forEach(function (record) {
        // Kinesis data is base64 encoded so decode here
        var payload = new Buffer(record.kinesis.data, 'base64');
        zlib.gunzip(payload, function (err, data) {
                console.log("new data2");
            if (!err) {
                console.log("new data3");
                console.log(data);
            }
            else {
                console.log("new data4");
                console.log(err, err.stack);
            }
        });
    });
    context.done();
};

Answers


Mark B February 2016

Move the context.done() call into your callback so that the Lambda function isn't terminated early. Like this:

function (event, context) {
    event.Records.forEach(function (record) {
        // Kinesis data is base64 encoded so decode here
        var payload = new Buffer(record.kinesis.data, 'base64');
        zlib.gunzip(payload, function (err, data) {
            console.log("new data2");
            if (!err) {
                console.log("new data3");
                console.log(data);
            }
            else {
                console.log("new data4");
                console.log(err, err.stack);
            }
            context.done();
        });
    });
};

Post Status

Asked in February 2016
Viewed 2,461 times
Voted 5
Answered 1 times

Search




Leave an answer