创建AWS sagemaker终端节点并使用AWS Lambda删除该终端节点

时间:2018-07-19 19:05:39

标签: amazon-web-services aws-lambda amazon-sagemaker

是否可以使用AWS lambda创建sagemaker端点?

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

2 个答案:

答案 0 :(得分:1)

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

在步进功能中有任务要

1。启动AWS Lambda到CreateEndpoint

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 |删除|失败)要么停止作业,要么继续轮询

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规则结合起来,我认为这很笨拙。

答案 1 :(得分:0)

虽然rajesh的答案更接近问题的要求,但我想补充一点,贤哲的人现在有一个批量转换工作。

此工作无需连续托管计算机,而是可以立即处理大型批处理的预测,而无需担心延迟。因此,如果问题的目的是在短时间内部署模型以预测固定的批次数量。这可能是更好的方法。

相关问题