Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoking SageMaker endpoint with data payload in S3 from a python boto client

I have an image that I upload to s3 in mybucket. Suppose my s3 endpoint for this data is s3://mybucket/imgname

Now I also have a model deployed in SageMaker at sagemaker-model-endpoint

I looked into examples of how to invoke this SageMaker endpoint from a boto client here but I am not sure how to specify the s3 path s3://mybucket/imgname in the invoke_endpoint call.

client = boto3.client("runtime.sagemaker", region_name = 's3.us-east-2.amazonaws.com')
client.invoke_endpoint(
      EndpointName=sagemaker-model-endpoint
      Body=payload,
      ContentType='image/jpg',
      Accept='Accept')

What should be the payload in this case? Where do I specify the s3 url?

like image 862
nad Avatar asked Dec 06 '25 18:12

nad


1 Answers

You need to have the bytes of the image, and after you get the image from S3 (S3 copy or wget), you can call:

with open(file_name, 'rb') as f:
    payload = f.read()
    payload = bytearray(payload)

client.invoke_endpoint(EndpointName=sagemaker-model-endpoint, 
                                   ContentType='application/x-image', 
                                   Body=payload)
like image 93
Guy Avatar answered Dec 09 '25 18:12

Guy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!