我尝试通过 Lambda 调用 SageMaker,但收到错误。
这是错误:
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_handler\n response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME,\n",
" File \"/var/runtime/botocore/client.py\", line 565, in _api_call\n return self._make_api_call(operation_name, kwargs)\n",
" File \"/var/runtime/botocore/client.py\", line 1021, in _make_api_call\n raise error_class(parsed_response, operation_name)\n"
]
}
模型端点来自预构建的模型-uri。
这是我的 Lambda 代码:
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
}
此外,我不确定 SageMaker 端点期望以什么格式接收 JSON 数据。
谢谢您的帮助!
为了调查导致“ModelError”的原因,您需要检查模型容器中的日志。来自端点的日志发送到“/aws/sagemaker/Endpoints/[EndpointName]”。请检查您是否在那里看到更具体的错误消息。
有关 SageMaker 在何处发出日志的更多信息,请参阅此文档页面: https://docs.aws.amazon.com/sagemaker/latest/dg/logging-cloudwatch.html