从AWS lambda发布到Kinesis Process已退出

时间:2017-07-28 17:21:57

标签: amazon-web-services aws-lambda amazon-kinesis

我正在尝试从aws lambda发布事件但是我收到以下错误:

Process exited before completing request

这是我的代码

exports.handler = (event, context, callback) => {
  kinesis.PutRecord({
    "Data": event,
    "PartitionKey" : "1",
    "StreamName": "TestStream"
  });
  context.done();
  callback(null, "");
}

1 个答案:

答案 0 :(得分:3)

您在context.done函数之前调用了callback,其中两个函数都是处理程序代码的退出回调函数。删除代码中的context.done,并执行以下更改。

const AWS = require('aws-sdk');
const kinesis = new AWS.Kinesis({apiVersion: '2013-12-02'});

exports.handler = (event, context, callback) => {
  kinesis.putRecord({
   "Data": event,
   "PartitionKey" : "1",
   "StreamName": "TestStream"
   }, 
   function(err, data) {
    if (err)
      console.log(err, err.stack); // an error occurred
    else  
      callback(null, data);        // successful response
   });
}