从 AWS lambda 发布到 Kinesis Process 已退出

Publishing from AWS lambda to Kinesis Process exited

我正在尝试从 aws lambda 发布事件,但出现以下错误:

Process exited before completing request

这是我的代码

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

您在 callback 函数之前调用了 context.done,其中两者都是处理程序代码的退出回调。删除代码中的 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
   });
}