Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push data from AWS lambda to Kinesis Firehose

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

like image 567
Asish Avatar asked Jul 11 '16 09:07

Asish


People also ask

How do I push data to Kinesis stream?

To put data into the stream, you must specify the name of the stream, a partition key, and the data blob to be added to the stream. The partition key is used to determine which shard in the stream the data record is added to. All the data in the shard is sent to the same worker that is processing the shard.

Can Lambda trigger Kinesis?

You can attach a Lambda function to a Kinesis stream to process data. Multiple Lambda functions can consume from a single Kinesis stream for different kinds of processing independently. These can be used alongside other consumers such as Amazon Kinesis Data Firehose.

Can Lambda read from firehose?

Kinesis Data Firehose can invoke your Lambda function to transform incoming source data and deliver the transformed data to destinations. You can enable Kinesis Data Firehose data transformation when you create your delivery stream.


1 Answers

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();
    });
};
like image 124
Asish Avatar answered Nov 10 '22 14:11

Asish