在 Postgres 内使用 aws sagemaker InvokeEndpoint 发出问题

问题描述 投票:0回答:1

我正在开展一项实验,将 ML 预测集成到我的 RDS Postgres 14.6.7 数据库中。我按照本教程进行操作,并成功加载数据、创建 sagemaker 模型、完成 sagemaker 培训并部署端点。一切看起来都很好。

然后我编写了一些代码来测试端点预测。

import boto3
import json

# Create a Boto3 client for SageMaker
client = boto3.client('sagemaker-runtime')

# Set the name of the SageMaker endpoint to invoke
endpoint_name = 'Custom-sklearn-model-2024-03-26-20-15-12'

# Set the content type of the input data
content_type = 'application/json'

# Hardcoded input data
input_data = [
    [1454.0, 1.0, 0.5, 1.0, 1.0, 0.0, 34.0, 0.7, 83.0, 4.0, 3.0, 250.0, 1033.0, 3419.0, 7.0, 5.0, 5.0, 1.0, 1.0, 0.0], 
    [1092.0, 1.0, 0.5, 1.0, 10.0, 0.0, 11.0, 0.5, 167.0, 3.0, 14.0, 468.0, 571.0, 737.0, 14.0, 4.0, 11.0, 0.0, 1.0, 0.0]
]

# Convert the input data to JSON format
payload = json.dumps(input_data)

# Invoke the SageMaker endpoint
response = client.invoke_endpoint(
    EndpointName=endpoint_name,
    ContentType=content_type,
    Body=payload
)

# Get the response from the SageMaker endpoint
result = response['Body'].read().decode('utf-8')

print(result)

此代码的输出为

[3, 0]

一切看起来都很好。我转到 RDS 集群来验证我是否具有 sagemaker 的 IAM 角色。这个角色已经存在并且对于 sagemaker 来说很活跃。

现在我将使用该角色在我的 SageMaker 端点上运行模拟来调用 InvokeEndpoint。我选择了角色并选择了 sagemaker 并将端点设置为特定端点的 arn。一切都会过去。

所以现在我的数据库应该能够调用它了。在 PGAdmin 中,我安装了 aws_ml 扩展,现在可以访问 aws_sagemaker.invoke_endpoint 函数。

当我运行此查询时,我希望返回结果而不是超时。

SELECT aws_sagemaker.invoke_endpoint (
    'Custom-sklearn-model-2024-03-26-20-15-12',
    1,
    1454.0, 1.0, 0.5, 1.0, 1.0, 0.0, 34.0, 0.7, 83.0, 4.0, 3.0, 250.0, 1033.0, 3419.0, 7.0, 5.0, 5.0, 1.0, 1.0, 0.0
);

这是我得到的错误

'错误:invoke_endpoint 失败,并显示错误消息:“curlCode:28,已达到超时”'

我检查了端点的 cloudwatch 日志,但它从未到达该端点。我不明白它出了什么问题。数据库似乎没有使用 sagemaker 的角色。在一些mysql教程中,集群参数组中似乎有一个参数“aws_default_sagemaker_role”。不幸的是,该参数对我来说不可用,并且不确定我是否缺少配置默认 sagemaker 角色的内容。

postgresql amazon-rds amazon-sagemaker
1个回答
0
投票

我需要修改该数据库实例正在使用的安全组的传出规则。我刚刚打开了它的所有传出流量来验证它,它似乎有效。

© www.soinside.com 2019 - 2024. All rights reserved.