3

I have a endpoint up and running in AWS Sagemaker. However, I'm not sure how to send data to this endpoint and get back a prediction.

The documentation is also not clear on this. Any help would be appreciated.

Jaskaran Singh Puri
  • 729
  • 2
  • 11
  • 37

3 Answers3

1

As Guy suggested, use AWS SDKs to invoke Sagemaker endpoint and retrieve predictions.

To test using Postman, you can follow these steps:

  1. In 'Authorization' tab, select type as 'AWS Signature'.
  2. Enter your Access and Secret key of the IAM user which has permission to Sagemaker resources.
  3. Enter the AWS region. eg.us-east-1
  4. Enter 'Service Name' as 'sagemaker'
  5. Select the right content type. Some ML algorithms only accept 'text/csv'.
  6. Select request type as 'POST'
  7. Enter the Sagemaker Invocation url. eg:'https://runtime.sagemaker.us-east-1.amazonaws.com/endpoints/xgboost-xxxx-xx-xx-xx-xx-xx-xxx/invocations'

Here is how your Postman should look - Sagemaker endpoint request - Postman Screenshot

Priyank Kapasi
  • 1,773
  • 2
  • 18
  • 27
  • If it's possible to invoke an AWS SageMaker endpoint via Postman, it suggests that the AWS SDK is not needed, and that we should be able to call these endpoints using the usual cleint-side fetch API, which would be much easier. A fetch example invoking a SageMaker endpoint would be much appreciated. – Cybernetic Nov 10 '21 at 00:52
0

The way to call the endpoint is through the invoke-endpoint that you can find in Amazon SageMaker runtime API: https://docs.aws.amazon.com/sagemaker/latest/dg/API_runtime_InvokeEndpoint.html

You can use this API through different SDKs, including the CLI, JavaScript, Java, C#, Python and others.

Please note that you have a couple of SDKs versions for Python. One is based on the boto as you can see above, and the other python SDK is more concise and can be used inside of a Jypther notebook. See here for an example: https://docs.aws.amazon.com/sagemaker/latest/dg/tf-example1-invoke.html or https://docs.aws.amazon.com/sagemaker/latest/dg/mxnet-example-invoke.html

The simplest way to invoke the endpoint if you are not integrating it with an existing code in one of the languages above is to call it through a Lambda function. The lambda function should have the IAM permissions to call that specific endpoint, and then you can trigger the Lambda function from various sources such as API-GW, mobile device etc.

Guy
  • 12,388
  • 3
  • 45
  • 67
0

I am using Nodejs for invoking the sagemaker endpoint as below:

var AWS = require('aws-sdk');
var sageMakerRuntime = new AWS.SageMakerRuntime({region: 'us-east-1'});

var params = {
  Body: new Buffer('{"instances": [1.0,2.0,5.0]}'),
  EndpointName: 'EndpointName-XXX'
};

sageMakerRuntime.invokeEndpoint(params, function(err, data) {
  responseData = JSON.parse(Buffer.from(data.Body).toString('utf8'))
  console.log(responseData);
});
Biranchi
  • 16,120
  • 23
  • 124
  • 161