Amazon AWS Machine Learning HTTP request

3k views Asked by At

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"
}
2

There are 2 answers

1
Michael Dz On BEST ANSWER

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
}
0
vaquar khan On

Please check following link and validate your sigv4

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