Reputation: 31
I have a TensorFlow Model deployed with AWS SageMaker endpoint exposed . From Lambda Python I am using boto3 client to invoke the endpoint . The TensorFlow model accepts 3 inputs as follows
{'input1' : numpy array , 'input2' : integer ,'input3' :numpy array }
From Lambda using runtime.invoke_endpoint to invoke the SageMaker endpoint . Getting the error as Parse Error when the API is invoked from boto3client I tried serializing the data into csv format before calling the API endpoint
Below code written in Lambda
payload = {'input1': encoded_enc_inputstanza_in_batch,
'input2' : encoded_enc_inputstanza_in_batch.shape[1],
'input3' : np.reshape([[15]*20],20) }
infer_file = io.StringIO()
writer = csv.writer(infer_file)
for key, value in payload.items():
writer.writerow([key, value])
response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME,
ContentType='text/csv',
Body=infer_file.getvalue())
Additional Details These are the additional details - Sagemaker Model expects 3 fields as input - 'input1' - Numpy array 'input2' - Int data type , 'input3' - numpy array
Actual result -
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 143, in lambda_handler
Body=infer_file.getvalue())
File "/var/runtime/botocore/client.py", line 320, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 623, in _make_api_call
raise error_class(parsed_response, operation_name)
END RequestId: fa70e1f3-763b-41be-ad2d-76ae80aefcd0
Expected Result - Successful invocation of the API endpoint .
Upvotes: 0
Views: 702
Reputation: 51
After converting the data to text/csv format with comma delimited, have you updated the Endpoint to use the new model data? The input data needs to match the schema of the model. Is there comma in the "encoded_enc_inputstanza_in_batch" variable?
Upvotes: 0
Reputation: 12891
For text/csv the value for the Body argument to invoke_endpoint should be a string with commas separating the values for each feature. For example, a record for a model with four features might look like: 1.5,16.0,14,23.0. You can try the following:
dp = ','.join(str(a) for a in payload)
Upvotes: 0