Push data from AWS lambda to Kinesis Firehose

Asish picture Asish · Jul 11, 2016 · Viewed 7.3k times · Source

I have an apiGateway endpoint and I am sending some post request to the endpoint. The integration type for the apigateway is lambda function. I want the lambda function to listen to the post data coming on the apigateway and push those data to kinesis firehose.

Can anyone help me get a sample node js lambda code that will push the incoming data to kinesis firehose. I tried to search for this but could not get anything.

Thanks

Answer

Asish picture Asish · Jul 11, 2016

I got it.

This is a sample code :

var AWS = require('aws-sdk');
var firehose = new AWS.Firehose();

exports.handler = function(event, context) {
    var params = {
        DeliveryStreamName: <STRING>,
        Record: { 
            Data: decodeURIComponent(event)
        }
    };
    firehose.putRecord(params, function(err, data) {
        if (err) console.log(err, err.stack); // an error occurred
        else     console.log(data);           // successful response

        context.done();
    });
};