gpt4 book ai didi

amazon-web-services - 使用 AWS lambda 创建 AWS sagemaker 端点并删除它

转载 作者:行者123 更新时间:2023-12-05 05:15:42 27 4
gpt4 key购买 nike

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

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

最佳答案

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

在step函数中有任务要

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 | Creating | Updating | RollingBack | InService | Deleting | Failed)停止作业或继续轮询

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

关于amazon-web-services - 使用 AWS lambda 创建 AWS sagemaker 端点并删除它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51430151/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com