我正在尝试使用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
}
任何帮助将不胜感激。谢谢
出现错误是因为CloudSearch希望消息是一个对象数组,而是只发送一个对象。