I'm trying to extract the named entities from a given text using AWS comprehend using AWS lambda.
const s3 = new AWS.S3();
const comprehend = new AWS.Comprehend();
function prcObj(text) {
let res = [];
return comprehend.detectEntities({
LanguageCode: 'en',
Text: text
}).promise()
.then( async data => {
for(let i = 0; i < data.Entities.length; i++) {
let phrase = await data.Entities[i].Text;
res.push(phrase);
}
return res
})
.catch(err => {
return err;
});
}
If I use promise I'm getting promise as result. If I remove promise then I'am getting
2022-11-19T21:24:23.691Z efcf1adc-5be0-4e20-94e8-dbcf88a8bb55 ERROR Invoke Error {
"errorType": "TypeError",
"errorMessage": "comprehend.detectEntities(...).then is not a function",
"stack": [
"TypeError: comprehend.detectEntities(...).then is not a function",
" at prcObj (/var/task/index.js:22:12)",
" at Runtime.exports.handler (/var/task/index.js:48:21)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
}
What am I doing wrong here?