ozil
ozil

Reputation: 679

How to access/invoke a sagemaker endpoint without lambda?

based on the aws documentation, maximum timeout limit is less that 30 seconds in api gateway.so hooking up an sagemaker endpoint with api gateway wouldn't make sense, if the request/response is going to take more than 30 seconds. is there any workaround ? adding a lambda in between api gateway and sagemaker endpoint is going to add more time to process request/response, which i would like to avoid. also, there will be added time for lambda cold starts and sagemaker serverless endpoints are built on top of lambda so that will also add cold start time. is there a way to invoke the serverless sagemaker endpoints , without these overhead?

Upvotes: 4

Views: 6415

Answers (2)

Naveen Reddy Marthala
Naveen Reddy Marthala

Reputation: 3133

It is indeed possible to invoke sagemaker endpoints from sagemaker without using any other AWS services and that is also manifested by the fact that they have invocation URLs.

Here's how you set it up:

  1. create an user with only programmatic access and attach a policy json that should look something like below:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "sagemaker:InvokeEndpoint",
            "Resource": "arn:aws:sagemaker:<region>:<account-id>:endpoint/<endpoint-name>"
        }
    ]
} 

you can replace <endpoint-name> with * to let this user invoke all endpoints.

  1. use the ACCESS-KEY and SECRET-ACCESS-KEY to configure authorisation in postman like shown in this screenshot. also add the parameters in advanced tab like shown in the screenshot. enter image description here

  2. then fill up your body with the relevant content type.

  3. then add or remove additional headers like variant-name or model-name, if you have them set up and the headers should look like shown in this screenshot: enter image description here

  4. send the request to receive reponse like this enter image description here

URL and credentials in the above screenshots doesn't work anymore, duh!

and if you want code to invoke the endpoint directly using some back-end language, here's code for python.

Upvotes: 5

Olivier Cruchant
Olivier Cruchant

Reputation: 4047

You can connect SageMaker endpoints to API Gateway directly, without intermediary Lambdas, using mapping templates https://aws.amazon.com/fr/blogs/machine-learning/creating-a-machine-learning-powered-rest-api-with-amazon-api-gateway-mapping-templates-and-amazon-sagemaker/

You can also invoke endpoints with AWS SDKs (eg CLI, boto3), no need to do it for API GW necessarily.

Upvotes: 2

Related Questions