我正在尝试通过AWS Javascript SDK使用AWS Rekognition API,并在尝试启动其任何检测服务时收到UnknownError: Bad Request
。我想运行标签检测,但是尝试其他操作时遇到相同的错误,例如名人脸检测。我已经确保我的帐户可以访问Rekognition API,并确保我的凭据正确(或至少相同的凭据对于连接到同一帐户的S3都有效)。
我的代码
var aws = require('aws-sdk');
const region = 's3-us-west-2';
const bucket = process.env.S3_VIDEO_BUCKET;
var requesttoken = randString(10) //generates random string
var key = 'path/to/key.mp4';
// used to check for keys to available files
var service = new aws.S3({
accessKeyId: process.env.ACCESS_KEY,
secretAccessKey: process.env.ACCESS_SECRET,
region: region,
endpoint: 'https://'+region+'.amazonaws.com/',
})
var rekognition = new aws.Rekognition({
accessKeyId: process.env.ACCESS_KEY,
secretAccessKey: process.env.ACCESS_SECRET,
region: region,
endpoint: 'https://'+region+'.amazonaws.com/',
apiVersion: '2016-06-27'
})
// check that key is reachable in S3
this.service.getObject({Bucket:bucket,Key:key}, function(err, data){
if(err){
console.error(err, err.stack)
} else {
console.log(data)
}
})
var params = {
Video: {
S3Object: {
Bucket: bucket,
Name: key
}
},
ClientRequestToken: requesttoken,
NotificationChannel: {
RoleArn: 'arn:aws:sns:us-west-2:000000000:example',
SNSTopicArn: 'example'
}
};
rekognition.startContentModeration(params, (err,data)=>{
if (err) {console.log(err, err.stack); return;};
console.log(data)
})
运行此代码时,我得到
{ UnknownError: Bad Request
at Request.extractError
(/Users/username/Desktop/project_directory/node_modules/aws-sdk/lib/protocol/json.js:48:27)
at Request.callListeners (/Users/username/Desktop/project_directory/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at Request.emit (/Users/username/Desktop/project_directory/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/Users/username/Desktop/project_directory/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/Users/username/Desktop/project_directory/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/Users/username/Desktop/project_directory/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /Users/username/Desktop/project_directory/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/Users/username/Desktop/project_directory/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/Users/username/Desktop/project_directory/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/Users/username/Desktop/project_directory/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
message: 'Bad Request',
code: 'UnknownError',
statusCode: 400,
time: 2018-06-29T21:08:27.184Z,
requestId: '2809C3770B525EF0',
retryable: false,
retryDelay: 57.00430269412582 }
我的问题
是否有人熟悉Rekognition API / AWS和JS SDK,他们知道在这种情况下错误请求可能会指示什么? AWS文档中是否有什么地方可以解释此错误可能指示什么?
答案 0 :(得分:1)
从您的配置中删除端点,它会自动填写
此配置错误
var rekognition = new aws.Rekognition({
accessKeyId: process.env.S3_ACCESS_KEY,
secretAccessKey: process.env.S3_BUCKET_ACCESS_SECRET,
您的访问密钥ID应该是您的AWS访问密钥,而不是S3访问密钥。除非S3 env var指向您实际的AWS访问密钥(您可能应该重命名它们)