使用lambda函数调用sagemaker端点 [英] call sagemaker endpoint using lambda function
问题描述
我在S3中有一些数据,我想创建一个lambda函数来预测已部署的aws sagemaker端点的输出,然后将输出再次放入S3中.在这种情况下是否有必要创建一个
I have some data in S3 and I want to create a lambda function to predict the output with my deployed aws sagemaker endpoint then I put the outputs in S3 again. Is it necessary in this case to create an api gateway like decribed in this link ? and in the lambda function what I have to put. I expect to put (where to find the data, how to invoke the endpoint, where to put the data)
谢谢
推荐答案
您绝对不必在API Gateway中创建API.您可以使用invoke_endpoint()API直接调用端点,并传递端点名称,内容类型和有效负载.
you definitely don't have to create an API in API Gateway. You can invoke the endpoint directly using the invoke_endpoint() API, passing the endpoint name, the content type, and the payload.
例如:
import boto3
endpoint_name = <INSERT_ENDPOINT_NAME>
runtime = boto3.Session().client(service_name='sagemaker-runtime',region_name='us-east-1')
response = runtime.invoke_endpoint(EndpointName=endpoint_name, ContentType='application/x-image', Body=payload)
print(response['Body'].read())
更多使用Lambda函数的示例: https://medium.com/@julsimon/using-chalice-to-serve-sagemaker-predictions-a2015c02b033
More examples here using a Lambda function: https://medium.com/@julsimon/using-chalice-to-serve-sagemaker-predictions-a2015c02b033
这篇关于使用lambda函数调用sagemaker端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!