Lambda Function not able to invoke sagemaker endpoint

本秂侑毒 提交于 2020-01-06 04:54:05

问题


predict = [0.1,0.2]
payload = {
    "instances":    [
        {
            "features": predict
        }
    ]
}
response = linear_regressor.predict(json.dumps(payload))
predictions = json.loads(response)
print(json.dumps(predictions, indent=2))

The above code is able to invoke the endpoint which is the linear-learner endpoint and give the below result.

{
  "predictions": [
    {
      "score": 0.13421717286109924
    }
  ]
}

But when I try to invoke the endpoint using below lambda function,

import json 
import io
import boto3 

client = boto3.client('runtime.sagemaker')

def lambda_handler(event, context):
    print("Received event: " + json.dumps(event, indent=2))

    #data = json.loads(json.dumps(event))
    #payload = data['data']
    #print(payload)

    response = client.invoke_endpoint(EndpointName='linear-learner-2019-12-12-16-xx-xx-xxx',
                                  ContentType='application/json',
                                  Body=json.dumps(event))
    return response

I get the following error,

    An error occurred during JSON serialization of response: 
<botocore.response.StreamingBody object at 0x7fc941e7e828> is not JSON serializable

The input for the lambda function is the same,

{
  "instances": [
    {
      "features": [
        0.1,
        0.2
      ]
    }
  ]
}

Not sure what is causing the issue here. Any help would be appreciated, Thanks in advance.

来源:https://stackoverflow.com/questions/59379081/lambda-function-not-able-to-invoke-sagemaker-endpoint

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