带translateText的参数中的意外键1-10

时间:2019-05-13 09:39:25

标签: amazon-web-services aws-sdk aws-sdk-js

所以我只是运行一个函数来使用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中的错误:

https://pastebin.com/wLJhTLFR

完整功能页:

https://pastebin.com/SmSDF04i

1 个答案:

答案 0 :(得分:1)

应该是:

const translated = await translate.translateText(params.Item).promise();

请参见translateText,从中可以看到它期望一个包含SourceLanguageCodeTargetLanguageCodeText的对象,就像您{{1 }}变量。