问题
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