Search code examples
aws-lambdaamazon-kinesis-firehose

Firehose not pushing data into s3 through Lambda?


I am trying to invoke kinesis through my lambda function . Here is my code

const AWS = require( 'aws-sdk' );
AWS.config.update({ region: 'us-east-1' });
var firehose = new AWS.Firehose();
exports.handler = async (event,context,callback) => {
    // TODO implement
    const response = {
        statusCode:200,
        Name:event.Name,
        Value:event.Value
    };
const params = {
  DeliveryStreamName: 'kinesis-fh-pika', 
  Record: { Data: new Buffer(JSON.stringify(response)) }
};

firehose.putRecord(params, (err, data) => {
if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);
});
};

Here is my Events

{
  "Name": "sara",
  "Value": 10
}

I am not getting any error in the lambda. It is always showing the reponse as null. I even tried enabling logs but didnt find any weird behaviour .

Am i missing anything ?

Thanks


Solution

  • I can able to resolve my question . All i am missing is an callback call . It seems the putRecord is only happening when it is getting some response callback.Here is the working code

    const AWS = require( 'aws-sdk' );
    AWS.config.update({ region: 'us-east-1' });
    var firehose = new AWS.Firehose();
    exports.handler = async (event,context,callback) => {
        // TODO implement
        const response = {
            statusCode:200,
            Name:event.Name,
            Value:event.Value
        };
    const params = {
      DeliveryStreamName: 'kinesis-fh-pika', 
      Record: { Data: new Buffer(JSON.stringify(response)) }
    };
    
    firehose.putRecord(params, (err, data) => {
    if (err) console.log(err, err.stack); // an error occurred
      else     console.log(data);
    });
    callback(null,"success");
    };