10

I have created AWS Machine Learning model with working real-time endpoint. I want to consume created service via HTTP request. For testing purpose I'm using Postman, I've created request according to Amazon's API documentation but every time I get the same exception: UnknownOperationException. While I'm using Python SDK the service is working fine. Below example that gets model info.

That's my request (fake credentials):

POST  HTTP/1.1
Host: realtime.machinelearning.us-east-1.amazonaws.com
Content-Type: application/json
X-Amz-Target: AmazonML_20141212.GetMLModel
X-Amz-Date: 20170714T124250Z
Authorization: AWS4-HMAC-SHA256 Credential=JNALSFNLANFAFS/20170714/us-east-1/AmazonML/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-target, Signature=fiudsf9sdfh9sdhfsd9hfsdkfdsiufhdsfoidshfodsh
Cache-Control: no-cache
Postman-Token: hd9sfh9s-idsfuuf-a32c-31ca-dsufhdso

{
   "MLModelId": "ml-Hfdlfjdof0807",
   "Verbose": true
}

Exception I get:

{
    "Output": {
        "__type": "com.amazon.coral.service#UnknownOperationException",
        "message": null
    },
    "Version": "1.0"
}
Michael Dz
  • 3,655
  • 8
  • 40
  • 74
  • Your content type should be `application/x-amz-json-1.1` – Joshua Jones Jul 19 '17 at 17:37
  • @jjones doesn't work, now I get this error: `"__type": "UnknownOperationException"` – Michael Dz Jul 20 '17 at 08:29
  • review the documentation here: http://docs.aws.amazon.com/machine-learning/latest/APIReference/API_GetMLModel.html – Joshua Jones Jul 20 '17 at 13:23
  • 1
    I will note though, that the AWS documentation is notoriously awful. Their HTTP request samples often have invalid values. – Joshua Jones Jul 20 '17 at 13:29
  • Totally agree, I've gone through entire documentation but still couldn't find a solution. I had no problems with their API Gateway but while dealing with ML service I can't execute even a simple request. – Michael Dz Jul 20 '17 at 14:22
  • Instead of using a POST request, do it as a GET request. I just tested it as a post and got the same unknownoperationexception, but when I changed it to a GET, I got a missingauthenticationtokenexception, which possibly means it would work if I had the right authentication key. – Myke Black Jul 25 '17 at 18:03

2 Answers2

1

After doing research on AWS forum I've found some similar HTTP requests. Turns out I had 3 incorrect parameters.

  1. Host address should be:

Host: machinelearning.us-east-1.amazonaws.com

  1. Content type:

Content-Type: application/x-amz-json-1.1

  1. In credentials parameters target service has to be specified as machinelearning

Short instruction how to setup Postman's request:

  1. In Authorization tab choose AWS Signature and fill in AccessKey and SecrectKey. In Service Name field write machinelearning. Click Update Request, this will update your header.

  2. In Headers tab add two headers:

    Key: X-Amz-Target, Value: AmazonML_20141212.GetMLModel

    Key: Content-Type, Value: application/x-amz-json-1.1

  3. Add body:

{ "MLModelId": "YOUR_ML_MODEL_ID", "Verbose": true }


Correct HTTP request below:

POST  HTTP/1.1
Host: machinelearning.us-east-1.amazonaws.com
X-Amz-Target: AmazonML_20141212.GetMLModel
Content-Type: application/x-amz-json-1.1
X-Amz-Date: 20170727T113217Z
Authorization: AWS4-HMAC-SHA256 Credential=JNALNFAFS/20170727/us-east-1/machinelearning/aws4_request, 
SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-target, 
Signature=fiudsf9sdfh9sdhfsd9hfsdkfdsiufhdsfoidshfodsh
Cache-Control: no-cache
Postman-Token: hd9sfh9s-idsfuuf-a32c-31ca-dsufhdso

{
   "MLModelId": "ml-Hfdlfjdof0807",
   "Verbose": true
}
Michael Dz
  • 3,655
  • 8
  • 40
  • 74
  • After I did the above, when trying to use real-time prediction, I was getting error: `"class com.amazon.coral.value.json.numbers.TruncatingBigNumber can not be converted to an String"`. This turned out to be because Machine Learning requires numbers in the JSON to be encoded as strings. (or maybe this is always true of x-amz-json-1.1? I can't find any spec for that particular flavor of JSON...) – Kip Sep 20 '18 at 21:41
0

Please check following link and validate your sigv4

http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html

vaquar khan
  • 10,864
  • 5
  • 72
  • 96