【问题标题】:I cannot handling this error when i'm trying to upload a document on cloudsearch当我尝试在 cloudsearch 上上传文档时,我无法处理此错误
【发布时间】:2019-02-21 08:30:21
【问题描述】:

我正在尝试使用 Aws lambda 函数对 cloudsearch 进行上传测试。该函数应该在触发 dynamodb 更新时将 dynamodb 表作为 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
}

任何帮助将不胜感激。谢谢

【问题讨论】:

  • 已解决。此错误是由错误的 JSON 结构引起的。

标签: node.js amazon-web-services amazon-dynamodb aws-lambda amazon-cloudsearch


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-06-02
    • 1970-01-01
    • 2023-03-23
    • 2021-03-30
    • 2011-07-12
    • 2020-12-16
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多