angular - 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');
});
解决方案
推荐阅读
- java - 调用@Sheduled 方法后未找到“强制”的现有事务
- r - 用数据框中的值替换向量的元素
- javascript - 从字符串重新实例化自定义类
- python - 显示无法与 pyvirtualdisplay 一起使用:“XStartTimeoutError:无法在显示“:1001”上启动 X(xdpyinfo 检查失败)”
- javascript - jQuery scrollTop 仅在 DevTools 在 Edge 中打开时有效
- bash - 这个 bash 行长度限制来自哪里?
- awk - awk 比较两个文件中的两列打印结果
- android - 从另一个应用程序的活动中获取数据?
- python - Django 2.1 使用 makemigrations 创建的迁移未显示在迁移文件夹中
- html - 如何解决 HTML/CSS 中的边距问题和 div 问题?