call sagemaker endpoint using lambda function

為{幸葍}努か 提交于 2019-12-13 03:34:02

问题


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)

Thanks


回答1:


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.

For example:

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())

More examples here using a Lambda function: https://medium.com/@julsimon/using-chalice-to-serve-sagemaker-predictions-a2015c02b033



来源:https://stackoverflow.com/questions/54558832/call-sagemaker-endpoint-using-lambda-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!