1

I am attempting to use AWS Rekognition API through the AWS Javascript SDK and am receiving UnknownError: Bad Request when I attempt to start any of their detections services. I want to run label detection, but have the same error while attempting the others, such as celebrity face detection. I have made sure that my account has access to the Rekognition API and made sure that my credentials are correct (or at least the same credentials work for S3 attached to the same account).

My Code

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

When I run this code I get

{ 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 }

My Question(s)

Is anyone familiar enough with the Rekognition API/AWS in conjunction with the JS SDK that they know what Bad Request might be indicating in this circumstance? Is there somewhere in the AWS Documentation that explains what this error might indicate?

1 Answer 1

1

Remove endpoint from your config, its filled in automatically

Also this config is wrong

var rekognition = new aws.Rekognition({
accessKeyId: process.env.S3_ACCESS_KEY,
secretAccessKey: process.env.S3_BUCKET_ACCESS_SECRET,

Your access key ID should be your AWS access key not S3 access key. Unless the S3 env vars point to your actual AWS access keys (you should probably rename them)

Sign up to request clarification or add additional context in comments.

5 Comments

Yes. Plus, the documentation says: endpoint (String) — The endpoint URI to send requests to. The default endpoint is built from the configured region. The endpoint should be a string like 'https://{service}.{region}.amazonaws.com'
Thanks for the response! When I remove endpoint from the params I receive: UnknownError: Moved Permanently . You are correct in assuming that the S3_access_key is the same as the AWS access key. I recently started trying to use Rekognition and just haven't gotten around to updating the variable names.
Checked with AWS Docs and this points to the endpoint being incorrect. Could the endpoint be changed such that the auto fill endpoint is incorrect? I also checked by putting in 'https://rekognition.'+region+'.amazonaws.com' and it also returned UnknownError: Moved Permanently . Where could I check what the proper endpoint is?
Rekognition endpoints: docs.aws.amazon.com/general/latest/gr/… S3 endpoints: docs.aws.amazon.com/general/latest/gr/rande.html#s3_region Moved permanently might refer to the S3 command as well so put a console.log('S3')/console.log('Rekognition') before each error so you can narrow it down.
my region variable had the s3 baked into it, so setting it as the region for rekognition was messing it up. All fixed!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.