简体   繁体   English

调用 InvokeEndpoint 操作时发生错误 (ModelError):收到服务器错误 (500)。 从 lambda+ api 网关调用端点

[英]An error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (500). Calling the endpoint from lambda+ api gateway

My sagemaker endpoint seems to be working while calling from lambda function but when I am using same payload from api gateway rest api (rest api deployed on api gateway as ANY Method with LAMBDA API INTEGRATION ENABLED), it is giving following error My sagemaker endpoint seems to be working while calling from lambda function but when I am using same payload from api gateway rest api (rest api deployed on api gateway as ANY Method with LAMBDA API INTEGRATION ENABLED), it is giving following error

Part of lambda function code from where I am calling SageMaker Endpoint我调用 SageMaker 端点的部分 lambda function 代码

@app.post("/dept_predictor")
@tracer.capture_method
def dept_predictor():
    # post_data: dict = app.current_event.json_body
    # try:
        print("Received event: " + json.dumps( app.current_event.body, indent=2))
        payload = app.current_event.body
        print(payload)
        # raise Exception('Malformed input ...')
    
        response  = runtime_client.invoke_endpoint(EndpointName=ENDPOINT_NAME, 
                                                  ContentType='application/json', 
                                                  Body=json.dumps(payload),
                                                  Accept='Accept')
        print(response)

Lambda function CloudWatch log after calling lambda function from api gateway Lambda function 从 api 网关调用 lambda function 后的 CloudWatch 日志

[ERROR] ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (500) from model with message "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>

SageMaker Endpoint Cloudwatch log SageMaker 端点 Cloudwatch 日志

2023-01-19T00:14:05.961+05:30   Loading the hash vectorizer model ...

2023-01-19T00:14:05.961+05:30   2023-01-18 18:44:05,959 ERROR - sklearn_functions - Exception on /invocations [POST]

2023-01-19T00:14:05.961+05:30   Traceback (most recent call last): File "/miniconda3/lib/python3.7/site-packages/sagemaker_containers/_functions.py", line 93, in wrapper return fn(*args, **kwargs) File "/opt/ml/code/sklearn_functions.py", line 130, in input_fn pname = json.loads(request_body)["product_name"]

2023-01-19T00:14:05.962+05:30   TypeError: string indices must be integers

2023-01-19T00:14:05.962+05:30   During handling of the above exception, another exception occurred:

2023-01-19T00:14:05.962+05:30   Traceback (most recent call last): File "/miniconda3/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/miniconda3/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/miniconda3/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File "/miniconda3/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise raise value File "/miniconda3/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/miniconda3/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/miniconda3/lib/python3.7/site-packages/sagemaker_containers/_transformer.py", line 200, in transform self._model, request.content, request.content_type, request.accept File "/miniconda3/lib/python3.7/site-packages/sagemaker_containers/_transformer.py", line 227, in _default_transform_fn data = self._input_fn(content, content_type) File "/miniconda3/lib/python3.7/site-packages/sagemaker_containers/_functions.py", line 95, in wrapper six.reraise(error_class, error_class(e), sys.exc_info()[2]) File "/miniconda3/lib/python3.7/site-packages/six.py", line 702, in reraise raise value.with_traceback(tb) File "/miniconda3/lib/python3.7/site-packages/sagemaker_containers/_functions.py", line 93, in wrapper return fn(*args, **kwargs) File "/opt/ml/code/sklearn_functions.py", line 130, in input_fn pname = json.loads(request_body)["product_name"]

2023-01-19T00:14:05.962+05:30   10.32.0.2 - - [18/Jan/2023:18:44:05 +0000] "POST /invocations HTTP/1.1" 500 290 "-" "AHC/2.0"

2023-01-19T00:14:05.962+05:30   sagemaker_containers._errors.ClientError: string indices must be integers

I tried to check this similar GitHub issue which is not resolved yet.我试图检查这个尚未解决的类似GitHub 问题 Any lead on this is highly appreciated.对此的任何领先都表示高度赞赏。 Thanks!谢谢!

Figured out the issue.想通了这个问题。 When I am calling from using api gate rest api same payload is getting transfer without using lambda api proxy integration and ANY method setup as string.当我使用 api 门 rest api 调用时,无需使用 lambda api 代理集成和任何方法设置为字符串即可传输相同的有效负载。 So converting string payload to dict payload solved the issue所以将字符串有效负载转换为字典有效负载解决了这个问题

payload = json.loads(payload)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SageMaker Endpoint:调用 InvokeEndpoint 操作时 ServiceUnavailable 503 - SageMaker Endpoint: ServiceUnavailable 503 when calling the InvokeEndpoint operation 调用 DescribeLaunchTemplates 操作时发生错误(UnauthorizedOperation)? - An error occurred (UnauthorizedOperation) when calling the DescribeLaunchTemplates operation? 调用 DescribeTaskDefinition 操作时发生错误(ClientException) - An error occurred (ClientException) when calling the DescribeTaskDefinition operation 调用 PutSubscriptionFilter 操作时发生错误(InvalidParameterException) - An error occurred (InvalidParameterException) when calling the PutSubscriptionFilter operation AWS Lambda python boto3 dynamodb 表扫描 - 调用扫描操作时发生错误(ValidationException):ExpressionAttributeNames - AWS Lambda python boto3 dynamodb table scan - An error occurred (ValidationException) when calling the Scan operation: ExpressionAttributeNames 调用HeadObject操作时出现错误(404):Key“”不存在 - An error occurred (404) when calling the HeadObject operation: Key "" does not exist 尝试在 AWS Lambda Lambda function 中下载文件时如何修复“ClientError:调用 HeadObject 操作时发生错误(403):禁止” - how to fix "ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden" when trying to download file in AWS Lambda function 调用 UploadServerCertificate 操作时发生客户端错误(SignatureDoesNotMatch) - A client error (SignatureDoesNotMatch) occurred when calling the UploadServerCertificate operation AWS timestream-write 获取“调用 DescribeEndpoints 操作时发生错误 (AccessDeniedException):不允许执行此操作。” - AWS timestream-write gets "An error occurred (AccessDeniedException) when calling the DescribeEndpoints operation: This operation is not allowed." Amazon Lex 错误:调用 PutIntent 操作时发生错误 (BadRequestException):RelativeId 与 Lex ARN 格式不匹配 - Amazon Lex Error: An error occurred (BadRequestException) when calling the PutIntent operation: RelativeId does not match Lex ARN format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM