0

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');
    });
jediknight562
  • 121
  • 1
  • 9
  • What happens if, for the promise version, you start the request again from scratch without the callback, `rekognition.detectLabels(params).promise().then(...)`? ie, pass a callback or chain `.promise()` but don't mix-and-match. – Roamer-1888 May 31 '18 at 18:31
  • @Roamer-1888 Unfortunately, the same error pops. The promise seems to result in the error for some reason. – jediknight562 May 31 '18 at 18:43
  • If you need a promise but `rekognition.detectLabels(params).promise().then(...)` is unreliable, you may be forced to [promisify](https://stackoverflow.com/a/22519785/3478010) `rekognition.detectLabels(params, nodeBack)`. Doing so is pretty trivial. – Roamer-1888 May 31 '18 at 20:20
  • 1
    Thanks @Roamer-1888. I might give that a try. I ended up workings around it without using Promise using the code above. Promise should work out of the box but this accomplishes largely the same result. – jediknight562 Jun 02 '18 at 20:32

0 Answers0