Amazon web services 创建AWS sagemaker端点,并使用AWS lambda删除该端点

Amazon web services 创建AWS sagemaker端点,并使用AWS lambda删除该端点,amazon-web-services,aws-lambda,amazon-sagemaker,Amazon Web Services,Aws Lambda,Amazon Sagemaker,有没有办法使用AWS lambda创建sagemaker端点 lambda的最大超时限制为300秒,而我的现有型号需要5-6分钟来承载?一种方法是将lambda和Step函数与等待状态结合起来,以创建sagemaker端点 在步骤函数中,有要执行的任务 一,。启动AWS Lambda以创建端点 import time import boto3 client = boto3.client('sagemaker') endpoint_name = 'DEMO-imageclassificatio

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


lambda的最大超时限制为300秒,而我的现有型号需要5-6分钟来承载?

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

在步骤函数中,有要执行的任务

一,。启动AWS Lambda以创建端点

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
二,。等待任务等待X分钟

三,。使用Lambda检查EndpointStatus的另一项任务失败,根据EndpointStatus(服务中断|创建|更新|回滚|服务内|删除|)停止作业或继续轮询

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

虽然rajesh的答案更接近问题的要求,但我想补充一点,sagemaker现在有一个批量转换任务


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

我们可以使用等待任务,但lambda超时为5分钟,创建端点需要5-6分钟。因此Lambda给定超时错误如何使用云监视规则?在cloud Watch中创建规则时,我在服务下拉列表中找不到SageMaker选项。我已用代码更新了答案。CreateEndpoint是一个异步调用,它只返回端点的ARN。在第二个lambda中,您将实现可以检查端点创建状态的轮询器。在step函数中,您将添加等待时间。此外,CloudFormation(CFN)现在支持SageMaker,您可以通过CFN创建端点。主要目的是以编程方式自动创建端点。那么有什么方法可以做到这一点吗?这取决于你想如何使用你的模型。批处理转换作业不需要终结点。因此,没有必要等待它的创建。它自己创建一个端点,并为调用提供预定义的数据。我同意丹尼斯·欧共体的观点。如果您的需求是执行批处理预测,那么新的功能批处理转换将是理想的,并且端点由其自身提供/销毁。请注意,到目前为止,仅支持S3作为输入。