Error with invoking a Deployed InService SageMaker Canvas ML Model Endpoint: Received Server Error (500) from primary and could not load the entire response body.

0

Hey, so I am trying to make requests and receive responses from an Endpoint that I have deployed for an ML Model that I have made on SageMaker Canvas, through my Flask Web Application.

This is the code on my Flask Application app.py as of now:

Initialize the SageMaker client

    client = boto3.client("runtime.sagemaker", aws_access_key_id=AWS_ACCESS_KEY, aws_secret_access_key=AWS_SECRET_KEY, region_name=AWS_REGION)

Create a list of lists where the first list represents column names and the second list represents values

    data = [['artist', 'album'], ['Happy', 0.843]]

    # Create a DataFrame from the list of lists
    df = pd.DataFrame([data[1]], columns=data[0])

    # Convert DataFrame to CSV format
    csv_data = df.to_csv(header=False, index=False).encode("utf-8")

Invoke the SageMaker endpoint with the modified input data

    response = client.invoke_endpoint(
        EndpointName="canvas-canvas-NewDeploymentTry1Please",
        ContentType="text/csv",
        Body=csv_data,
        Accept="application/json"
    )

But, the error received is:

botocore.errorfactory.ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (500) from primary and could not load the entire response body.

The Endpoint is InService too.

Any help at all is much appreciated. Thanks so so much, in advance.

Archisa
gefragt vor 4 Monaten752 Aufrufe
1 Antwort
0

Hello,

So the issue here is most likely with your inference code and how you are parsing/transforming the data coming in. Your endpoint is up and running but the format in which you are feeding it data is confusing it. The endpoint is expecting encoded data thus you need to convert your payload into the appropriate data format, there are two manners in which you can approach this.

Use a serializer, when creating your endpoint with the predictor class you want to use the SageMaker Serializer to automatically encode/decode your data, this is configured while creating your endpoint.

If you choose not to use the serializer you want to encode the data on your own using something such as json.dumps(payload) to encode your data properly before sending the data to the endpoint.

Extra Resources: SageMaker Serializers: https://sagemaker.readthedocs.io/en/stable/api/inference/serializers.html

Hope this helps!

AWS
beantwortet vor 3 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen