John doe
John doe

Reputation: 3880

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

I'm trying to do an upload test on cloudsearch by using a Aws lambda function. The function is supposed to upload a dynamodb table as a JSON document to cloudsearch when a dynamodb update is triggered but i get an error and i'm trying to figure out what does it means and how to get rid of.

For the moment, i'm working with a config test event

Here is the lambda function :

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

The error message i get :

{
  "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
}

Any help will be appreciated. Thanks

Upvotes: 1

Views: 1477

Answers (1)

George Olah
George Olah

Reputation: 607

the error appears because CloudSearch expects the message to be an array of objects, but instead you were sending just one object.

Upvotes: 5

Related Questions