当我尝试在 cloudsearch 上上传文档时无法处理此错误

I cannot handling this error when i'm trying to upload a document on cloudsearch

我正在尝试使用 Aws lambda 函数在 cloudsearch 上进行上传测试。当触发 dynamodb 更新时,该函数应该将 dynamodb table 作为 JSON 文档上传到 cloudsearch 但我收到错误,我试图弄清楚它是什么意思以及如何获得摆脱。

目前,我正在处理配置测试事件

这是 lambda 函数:

var aws = require('aws-sdk');



exports.handler = function(event,context){
     var cloudsearchdomain = new aws.CloudSearchDomain({endpoint: 'doc-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.cloudsearch.amazonaws.com'});

    
    var documents = {id : event.Records[0].dynamodb.Keys.Id.N};
    documents.type = "add";
    documents.fields = {
        "message" : "Hello",
        "id" : "100",
        "name" : "name"
    }
    var params = {contentType: 'application/json', documents : JSON.stringify(documents) };
    console.log('uploading documents to cloudsearch domain', params);
    cloudsearchdomain.uploadDocuments(params, function(err, data) {
        if(err) {
            console.log('Error uploading documents to cloudsearch', err, err.stack);
            context.done(null,err);
        } else {
            context.done(null,"Successfully processed");  
        }
        
    });
 
}

我收到的错误消息:

{
  "message": "{ [\"The first non-whitespace character in the file must be '['\"] }",
  "code": "DocumentServiceException",
  "time": "2016-04-26T10:56:18.858Z",
  "requestId": "814bp1d66-0basd-11e6-b7fc-b9b1ad0761693",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 17.98068769276142
}

如有任何帮助,我们将不胜感激。谢谢

出现错误是因为 CloudSearch 期望消息是一组对象,但您只发送了一个对象。