我使用 boto3 SageMaker 客户端的 update_endpoint 方法。
import boto3
client = boto3.client('sagemaker')
endpoint_name = 'my-endpoint'
desired_status = 'OutOfService'
response = client.update_endpoint(
EndpointName=endpoint_name,
DesiredStatus=desired_status
)
print(response)
Response { "errorMessage": "Syntax error in module 'lambda_function': cannot assign to operator (lambda_function.py, line 6)",
我正在寻找一种安排 SageMaker Endpoint 启动和停止的方法。 请帮助我是否有任何方法可以将欲望计数设置为零或停止端点?
首先 - 我不明白您发布的代码应该如何工作。
desired_status
方法中没有update_endpoint()
参数。
要真正解决您的问题,我建议使用
EventBridge
调度程序。使用一个针对 sagemaker:createEndpoint
方法的调度程序,以及一个针对 sagemaker:deleteEndpoint
方法的调度程序。
由于创建和调用
SageMaker
端点都是通过其名称完成的,因此完全删除它是完全可以的,以防暂时不需要它。您应该能够毫无问题地重新创建它。
我建议您查看 SageMaker 异步端点/无服务器端点。对于异步端点,通过适当的自动缩放策略,您可以在没有流量时将实例数量减少到零,从而避免收费。
在无服务器端点中,您无需在端点后面配置实例,它们会像 Lambda 函数一样自动缩放和拆卸。
https://docs.aws.amazon.com/sagemaker/latest/dg/async-inference.html https://docs.aws.amazon.com/sagemaker/latest/dg/serverless-endpoints.html
我正在分享创建代码来管理 SageMaker 端点的经验。我使用 AWS Lambda 和事件计划程序触发器来计划端点的启动和删除。
下面是使用适用于 AWS 的 Boto3 库自动创建和删除 SageMaker 端点的 Python 脚本。
端点创建脚本:
import boto3
endpoint_config_name = "your_endpoint_config_name"
sagemaker = boto3.client("sagemaker")
endpoint_name = "endpoint-with-same-name"
sagemaker.create_endpoint(
EndpointName=endpoint_name,
EndpointConfigName=endpoint_config_name
)
端点删除脚本:
import boto3
endpoint_name = "endpoint-with-same-name"
sagemaker_client = boto3.client('sagemaker')
sagemaker_client.delete_endpoint(EndpointName=endpoint_name)
我成功实施了 EventBridge 调度程序来自动执行 SageMaker 端点的启动和删除流程。但是,我观察到 SageMaker 端点的创建大约需要 7 到 10 分钟。
谢谢大家