I am trying to invoke SageMaker through Lambda, but I am getting an error.
Here is the error:
Response
{
"errorMessage": "An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (400) from primary and could not load the entire response body. See https://us-east-1.console.aws.amazon.com/cloudwatch/home?region=us-east-1#logEventViewer:group=/aws/sagemaker/Endpoints/jira-endpoint in account xxxx for more information.",
"errorType": "ModelError",
"stackTrace": [
" File "/var/task/lambda_function.py", line 19, in lambda_handlern response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME,n",
" File "/var/runtime/botocore/client.py", line 565, in _api_calln return self._make_api_call(operation_name, kwargs)n",
" File "/var/runtime/botocore/client.py", line 1021, in _make_api_calln raise error_class(parsed_response, operation_name)n"
]
}
The model endpoint is from a prebuilt model-uri.
Here is my Lambda code:
import os, io, boto3, json, csv, base64
ENDPOINT_NAME = os.environ['ENDPOINT_NAME']
runtime= boto3.client('runtime.sagemaker')
def lambda_handler(event, context):
project = event['project']
# project = base64.b64decode(event['project'])
# timeline = base64.b64decode(event['timeline'])
# payload = """{}.
# Given the project description above, sugges a project tasklist to achieve the project goals.
# The project timeline is {} weeks.
# """.format(project, timeline)
payload = project
response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME,
Body=project, ContentType="text/csv")
result = json.loads(response["Body"].read().decode())
print(result)
return {
"statusCode": 200,
"headers": { "content-type": "application/json"},
"body": result
}
Also, I am not certain in what format the SageMaker endpoint expects to receive the JSON data.
Thank you for your help!