So I'm just running a function to translate text with AWS Translate. Here is my params and the call to the function:
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();
If I console log params.item.text
it outputs the right thing. But then when i run the translateText
function I get the error
* 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
Here is the error in cmd:
Full function page:
Should be:
const translated = await translate.translateText(params.Item).promise();
See translateText where you see that it expects an object containing SourceLanguageCode
, TargetLanguageCode
and Text
, just like the Item
key in your params
variable.