I'm attempting to utilize the Amazon Comprehend API using the AWS JavaScript SDK. However, I keep encountering
Uncaught (in promise): TypeError: undefined is not a constructor (evaluating 'new AWS.Comprehend...
' What am I doing incorrectly? Thank you very much.
All other services such as Polly and Rekognition are functioning correctly.
import * as AWS from 'aws-sdk';
....
getTextAnalysis(textToAnalyze) {
let awsCredentials = new AWS.Credentials("XXXXXXXXXXX", "XXXXXXXXX");
let settings = {
awsCredentials: awsCredentials,
awsRegion: "us-west-2"
}
AWS.config.credentials = settings.awsCredentials;
AWS.config.region = settings.awsRegion;
let sentimentAnalysis = new Promise(function (successCallback, errorCallback) {
var comprehend = new AWS.Comprehend({apiVersion: '2017-11-27'});
var params = {
LanguageCode: 'en',
Text: textToAnalyze
}
comprehend.detectSentiment(params, function (error, data) {
if (error) {
errorCallback(error)
} else {
console.log('comprehend: ' + JSON.stringify(data))
successCallback(data)
}
});
});
return sentimentAnalysis;
}