Using the AWS SDK for Javascript within Angular5 I'm seeing the following error when running DetectLabels or DetectFaces and returning to promise. When I print the return within the Detect function everything looks correct. The error only pops up when attempting to return the result into the promise.
"core.js:1449 ERROR Error: Uncaught (in promise):
InvalidSignatureException: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
InvalidSignatureException: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
I've confirmed the account seems to be working as expected as the log within the callback prints successfully and the bucket is in the same region as the rekognition. Anyone seen this before?
const rekognition = new Rekognition(
{
accessKeyId: this.accessKeyId,
secretAccessKey: this.secretAccessKey,
region: this.region,
signatureCache: false,
signatureVersion: 'v4'
}
);
const req = rekognition.detectLabels(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
return null;
}
// response prints to console successfully
console.log(JSON.stringify(data, null, '\t'));
});
req.promise().then(data => {
console.log(data); //Throws Exception
});
}
**** Workaround (working)
aws.service
rekogDetechLabels(): AWS.Request<Rekognition.DetectLabelsResponse, AWS.AWSError> {
const params = {
Image: {
S3Object: {
Bucket: this.bucket,
Name: this.fileName
}
}
};
const rekognition = new Rekognition(
{
accessKeyId: this.accessKeyId,
secretAccessKey: this.secretAccessKey,
region: this.region,
signatureCache: false,
signatureVersion: 'v4'
}
);
return rekognition.detectLabels(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
return false;
}
});
}
app.component
// Label Rekognition
const req = this.aws.rekogDetechLabels()
.on('success', response => {
console.log(response.data);
this.labels = (<Rekognition.DetectLabelsResponse>response.data).Labels;
}).on('error', err => {
console.log('Error with Rekognition');
});