AWS Rekognition返回无效签名Angular

时间:2018-05-31 15:58:46

标签: angular amazon-web-services typescript promise aws-sdk

在Angular5中使用AWS SDK for Javascript我在运行DetectLabels或DetectFaces并返回promise时看到以下错误。当我在Detect函数中打印返回时,一切看起来都是正确的。尝试将结果返回到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.

我已经确认该帐户似乎正在按预期工作,因为回调中的日志成功打印并且存储桶与重新识别位于同一区域。有人见过这个吗?

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
  });

}

****解决方法(工作)

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');
    });

0 个答案:

没有答案