【发布时间】: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