5

I've deployed an endpoint in sagemaker and was trying to invoke it through my python program. I had tested it using postman and it worked perfectly ok. Then I wrote the invocation code as follows

import boto3
import pandas as pd
import io
import numpy as np

def np2csv(arr):
    csv = io.BytesIO()
    np.savetxt(csv, arr, delimiter=',', fmt='%g')
    return csv.getvalue().decode().rstrip()


runtime= boto3.client('runtime.sagemaker')
payload = np2csv(test_X)

runtime.invoke_endpoint(
    EndpointName='<my-endpoint-name>',
    Body=payload,
    ContentType='text/csv',
    Accept='Accept'
)

Now whe I run this I get a validation error

ValidationError: An error occurred (ValidationError) when calling the InvokeEndpoint operation: Endpoint <my-endpoint-name> of account <some-unknown-account-number> not found.

While using postman i had given my access key and secret key but I'm not sure how to pass it when using sagemaker apis. I'm not able to find it in the documentation also.

So my question is, how can I use sagemaker api from my local machine to invoke my endpoint?

3 Answers 3

5

I also had this issue and it turned out to be my region was wrong.

Silly but worth a check!

Sign up to request clarification or add additional context in comments.

1 Comment

For me as well it turned out to be region selection problem, also if the end-point is in creation stage the same error.
4

When you are using any of the AWS SDK (including the one for Amazon SageMaker), you need to configure the credentials of your AWS account on the machine that you are using to run your code. If you are using your local machine, you can use the AWS CLI flow. You can find detailed instructions on the Python SDK page: https://aws.amazon.com/developers/getting-started/python/

Please note that when you are deploying the code to a different machine, you will have to make sure that you are giving the EC2, ECS, Lambda or any other target a role that will allow the call to this specific endpoint. While in your local machine it can be OK to give you admin rights or other permissive permissions, when you are deploying to a remote instance, you should restrict the permissions as much as possible.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "sagemaker:InvokeEndpoint",
            "Resource": "arn:aws:sagemaker:*:1234567890:endpoint/<my-endpoint-name>"
        }
    ]
}

2 Comments

This is not the answer to the problem. This might be the answer to another - policy-related issue.
There can be different reasons for such an error. It might be the configuration of the region as a few here reported, or it can be a misconfiguration of the credentials. as I tried to explain.
0

Based on @Jack's answer, I ran aws configure and changed the default region name and it worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.