所以我只是运行一个函数来使用AWS Translate翻译文本。这是我的参数以及对该函数的调用:
const translate = new AWS.Translate({ apiVersion: '2017-07-01' });
const data = JSON.parse(event.body);
const params = {
"TableName": "sites",
"Item": {
SourceLanguageCode: 'auto', /* required */
TargetLanguageCode: data.TargetLanguageCode, /* required */
Text: data.Text, /* required */
}
};
const translated = await translate.translateText(params.Item.Text).promise();
如果我控制台日志params.item.text
,它将输出正确的内容。但是然后当我运行translateText
函数时,我得到了错误
* UnexpectedParameter: Unexpected key '0' found in params
* UnexpectedParameter: Unexpected key '1' found in params
* UnexpectedParameter: Unexpected key '2' found in params
* UnexpectedParameter: Unexpected key '3' found in params
* UnexpectedParameter: Unexpected key '4' found in params
* UnexpectedParameter: Unexpected key '5' found in params
* UnexpectedParameter: Unexpected key '6' found in params
* UnexpectedParameter: Unexpected key '7' found in params
* UnexpectedParameter: Unexpected key '8' found in params
* UnexpectedParameter: Unexpected key '9' found in params
* UnexpectedParameter: Unexpected key '10' found in params
这是cmd中的错误:
完整功能页:
答案 0 :(得分:1)
应该是:
const translated = await translate.translateText(params.Item).promise();
请参见translateText,从中可以看到它期望一个包含SourceLanguageCode
,TargetLanguageCode
和Text
的对象,就像您{{1 }}变量。