Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon AWS Machine Learning HTTP request

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"
}
like image 290
Michael Dz Avatar asked Jul 14 '17 13:07

Michael Dz


People also ask

What does AWS use for machine learning?

PyTorch on AWS PyTorch is an open-source deep learning framework that makes it easy to develop machine learning models and deploy them to production.

Which optimization technique does Amazon machine learning use?

The optimization technique used in Amazon ML is online Stochastic Gradient Descent (SGD). SGD makes sequential passes over the training data, and during each pass, updates feature weights one example at a time with the aim of approaching the optimal weights that minimize the loss.


1 Answers

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
}
like image 185
Michael Dz Avatar answered Sep 20 '22 08:09

Michael Dz