Firehose是否通过Lambda将数据推入s3?

时间:2018-11-04 19:58:58

标签: aws-lambda amazon-kinesis-firehose

我试图通过lambda函数调用运动学。这是我的代码

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);
});
};

这是我的活动

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

我在lambda中没有任何错误。它始终将响应显示为null。我什至尝试启用日志,但没有发现任何奇怪的行为。

我错过了什么吗?

谢谢

2 个答案:

答案 0 :(得分:1)

它返回“ null”,因为您的Lambda函数未返回任何东西。

尝试

const AWS = require( 'aws-sdk' );
AWS.config.update({ region: 'us-east-1' });
var firehose = new AWS.Firehose();
exports.handler = async (event) => {
    // 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);
  }
 return response;
});
};

答案 1 :(得分:-1)

我可以解决我的问题。我只想念一个callback电话。看来putRecord仅在获得一些响应回调时才发生。这是工作代码

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");
};