AWS sagemaker abalone example pipeline endpoint json rejected

0

We've just created a train/build/deploy template in AWS SageMaker which provides a deployment of an Abalone model. We're trying to test it via the Test Inference endpoint, but the JSON there is rejected with the following message:

Error invoking endpoint: Received client error (415) from model with message "application/json is not an accepted ContentType: csv, libsvm, parquet, recordio-protobuf, text/csv, text/libsvm, text/x-libsvm, application/x-parquet, application/x-recordio-protobuf.". See https://eu-west-1.console.aws.amazon.com/cloudwatch/home?region=eu-west-1#logEventViewer:group=/aws/sagemaker/Endpoints/USEngProbOfConversion-staging in account 607522716587 for more information.

However the Test Inference endpoint only allows us to hit the endpoint with JSON - what can we do? Here's a screenshot (if this dropbox embed works):

but that's not working so here's the request dump:

{
  "body": {
    "s-x": "M",
    "length": 3,
    "diameter": 5,
    "height": 7,
    "whole_weight": 45,
    "shucked_weight": 34,
    "viscera_weight": 23,
    "shell_weight": 76
  },
  "contentType": "application/json",
  "endpointName": "USEngProbOfConversion-staging",
  "customURL": "",
  "customHeaders": [
    {
      "Key": "sm_endpoint_name",
      "Value": "USEngProbOfConversion-staging"
    },
    {
      "Key": "",
      "Value": ""
    }
  ]
}
asked 2 years ago1773 views
1 Answer
0

So as you saw already, the SageMaker Studio "Test inference" UI currently only supports JSON format... But this is a constraint of the UI, not your endpoint.

If you want to test your deployed endpoint with non-JSON data, you can do this from code (e.g. from a notebook):

  • Using the sagemaker Python SDK, create a Predictor specifying your endpoint name and the relevant de/serializers (from sagemaker.(de)serializers - for example sagemaker.serializers.CSVSerializer). Then call predictor.predict(data).
  • Using a boto3.client("sagemaker-runtime"), serialize your data to required format yourself (e.g. "M,3,5,7,45,34,23,76") and then call invoke_endpoint().

This would be necessary if you're using a pre-built algorithm that doesn't support JSON as a request/response format. Since you're using the Abalone pipeline example, I guess it's likely you're using XGBoost as a pre-built SageMaker algorithm?

Alternatively, if you're building a custom algorithm with your own training script OR would be interested in using XGBoost as a script-mode framework - more information in the SageMaker SDK doc), you may like to extend your algorithm to accept application/json requests and return JSON responses.

The process for this will vary a little by framework, but should be documented here for XGBoost. Essentially, you'll want to provide a script file e.g. inference.py which defines special functions input_fn() and output_fn(). You can provide implementations of these functions that accept application/json content types and de/serialize appropriately.

That way you could make your deployed endpoint support JSON format and therefore be able to use the test UI in SageMaker Studio.

AWS
EXPERT
Alex_T
answered 2 years ago
  • Thanks, that's super helpful - we've successfully used a boto3 client from a notebook in sagemaker to hit the endpoint based on your suggestion.

    What we'd really love to do is to be able to hit the endpoint from another machine outside sagemaker, e.g. on our dev machines or dev servers. Is there any documentation on that? We see this on StackOverflow https://stackoverflow.com/a/64907595/316729 that suggests one might pass AWS keys etc. into the boto3 client, but would love to see the official docs on the right way to do this.

    Many thanks in advance

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions