有没有办法使用AWS lambda创建sagemaker端点?
lambda的最大超时限制是300秒,而我现有的模型需要5-6分钟来托管?
发布于 2018-07-20 03:24:59
一种方法是将Lambda和Step函数与等待状态相结合,以创建sagemaker端点
在步骤函数中有任务
1.启动AWS Lambda to 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 status2.等待任务等待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规则的组合,我认为这将是笨拙的。
发布于 2018-07-20 14:42:55
虽然rajesh answer更接近问题的要求,但我想补充的是,sagemaker现在有一个批量转换作业。
该作业可以立即预测大量批处理,而不是持续托管一台机器,而无需考虑延迟。因此,如果问题背后的意图是在短时间内部署模型以预测固定数量的批次。这可能是更好的方法。
https://stackoverflow.com/questions/51430151
复制相似问题