首页 > 解决方案 > AWS Rekognition 返回无效签名 Angular

问题描述

在 Angular5 中使用适用于 Javascript 的 AWS 开发工具包我在运行 DetectLabels 或 DetectFaces 并返回承诺时看到以下错误。当我在 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.

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

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.服务

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

}

应用程序组件

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

标签: angularamazon-web-servicestypescriptpromiseaws-sdk

解决方案


推荐阅读