首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >创建AWS sagemaker端点并使用AWS lambda将其删除

创建AWS sagemaker端点并使用AWS lambda将其删除
EN

Stack Overflow用户
提问于 2018-07-20 03:05:39
回答 2查看 1.2K关注 0票数 2

有没有办法使用AWS lambda创建sagemaker端点?

lambda的最大超时限制是300秒,而我现有的模型需要5-6分钟来托管?

EN

回答 2

Stack Overflow用户

发布于 2018-07-20 03:24:59

一种方法是将Lambda和Step函数与等待状态相结合,以创建sagemaker端点

在步骤函数中有任务

1.启动AWS Lambda to CreateEndpoint

代码语言:javascript
运行
复制
import time
import boto3

client = boto3.client('sagemaker')

endpoint_name = 'DEMO-imageclassification-' + time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime())
endpoint_config_name = 'DEMO-imageclassification-epc--2018-06-18-17-02-44'
print(endpoint_name)

def lambda_handler(event, context):
    create_endpoint_response = client.create_endpoint(
        EndpointName=endpoint_name,
        EndpointConfigName=endpoint_config_name)
    print(create_endpoint_response['EndpointArn'])
    print('EndpointArn = {}'.format(create_endpoint_response['EndpointArn']))

    # get the status of the endpoint
    response = client.describe_endpoint(EndpointName=endpoint_name)
    status = response['EndpointStatus']
    print('EndpointStatus = {}'.format(status))
    return status

2.等待任务等待X分钟

3.另一个使用Lambda检查EndpointStatus的任务根据EndpointStatus (OutOfService |创建|更新| RollingBack | InService |删除|失败)停止作业或继续轮询

代码语言:javascript
运行
复制
import time
import boto3

client = boto3.client('sagemaker')

endpoint_name = 'DEMO-imageclassification-2018-07-20-18-52-30'
endpoint_config_name = 'DEMO-imageclassification-epc--2018-06-18-17-02-44'
print(endpoint_name)

def lambda_handler(event, context):
    # print the status of the endpoint
    endpoint_response = client.describe_endpoint(EndpointName=endpoint_name)
    status = endpoint_response['EndpointStatus']
    print('Endpoint creation ended with EndpointStatus = {}'.format(status))

    if status != 'InService':
        raise Exception('Endpoint creation failed.')


    # wait until the status has changed
    client.get_waiter('endpoint_in_service').wait(EndpointName=endpoint_name)


    # print the status of the endpoint
    endpoint_response = client.describe_endpoint(EndpointName=endpoint_name)
    status = endpoint_response['EndpointStatus']
    print('Endpoint creation ended with EndpointStatus = {}'.format(status))

    if status != 'InService':
        raise Exception('Endpoint creation failed.')

    status = endpoint_response['EndpointStatus']
  return 

另一种方法是AWS Lambda函数和CloudWatch规则的组合,我认为这将是笨拙的。

票数 2
EN

Stack Overflow用户

发布于 2018-07-20 14:42:55

虽然rajesh answer更接近问题的要求,但我想补充的是,sagemaker现在有一个批量转换作业。

该作业可以立即预测大量批处理,而不是持续托管一台机器,而无需考虑延迟。因此,如果问题背后的意图是在短时间内部署模型以预测固定数量的批次。这可能是更好的方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51430151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档