Quick Article: Setting up REST API Amazon Sagemaker

Abish Pius
2 min readMar 28, 2023
AWS Sagemaker

To send a REST API request for endpoint inference in Amazon SageMaker, you can follow these general steps:

  1. Create a SageMaker endpoint: First, you need to create an endpoint that will host your trained model. You can create an endpoint using the SageMaker console, the AWS CLI, or the SageMaker SDK.
  2. Prepare your input data: You need to prepare your input data in the format that your model expects. This may involve converting your data into a specific format such as CSV or JSON, or encoding it in a binary format if you are using an image-based model.
  3. Send a REST API request: You can send a REST API request to the SageMaker endpoint using tools such as cURL or Python requests. Your request should include the input data that you prepared in step 2.
  4. Receive the inference result: SageMaker will return the inference result in the response body of your REST API request. The format of the response will depend on the type of model you are using and how you configured the endpoint.

Here is an example of sending a REST API request for an endpoint inference using Python and the SageMaker SDK:

import boto3
import json
import numpy as np

# Create a SageMaker client
sm = boto3.client('sagemaker')

# Specify the endpoint name and input data
endpoint_name = 'your-endpoint-name'
data = np.random.rand(1, 10).tolist()

# Send a REST API request
response = sm.invoke_endpoint(

# Receive the inference result
result = json.loads(response['Body'].read().decode())

In this example, we created a SageMaker client and specified the endpoint name and input data. We then sent a REST API request using the invoke_endpoint method and received the inference result in the result variable. The input data is converted to a JSON string using the json.dumps method and sent as the request body with the ContentType parameter set to application/json.

Please consider supporting my cousin’s clothing brand, you do not need to make a purchase simply following this post on Instagram is a blessing: https://instagram.com/evestiaralifestyle?igshid=ZDdkNTZiNTM=

FREE PDF to Text CONVERTER Click here: Convert pdf to text for free!

Plug: Please purchase my book ONLY if you have the means to do so, I usually do not advertise, but I am struggling to stay afloat. Imagination Unleashed: Canvas and Color, Visions from the Artificial: Compendium of Digital Art Volume 1 (Artificial Intelligence Draws Art) — Kindle edition by P, Shaxib, A, Bixjesh. Arts & Photography Kindle eBooks @ Amazon.com.



Abish Pius

Data Science Professional, Python Enthusiast, turned LLM Engineer