-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless_endpoint.py
51 lines (39 loc) · 1.59 KB
/
serverless_endpoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Setup clients
import boto3
client = boto3.client(service_name="sagemaker")
runtime = boto3.client(service_name="sagemaker-runtime")
# Endpoint Configuration Creation
from time import gmtime, strftime
model_name="imba-image-classifier"
classifier_epc_name = "classifier-serverless-epc" + strftime("%Y-%m-%d-%H-%M-%S", gmtime())
endpoint_config_response = client.create_endpoint_config(
EndpointConfigName=classifier_epc_name,
ProductionVariants=[
{
"VariantName": "byoVariant",
"ModelName": model_name,
"ServerlessConfig": {
"MemorySizeInMB": 4096,
"MaxConcurrency": 1,
},
},
],
)
print("Endpoint Configuration Arn: " + endpoint_config_response["EndpointConfigArn"])
print("Endpoint config Name:", "", classifier_epc_name)
# Serverless Endpoint Creation
endpoint_name = "classifier-serverless-ep" + strftime("%Y-%m-%d-%H-%M-%S", gmtime())
print("Endpoint Name:", "", endpoint_name)
create_endpoint_response = client.create_endpoint(
EndpointName=endpoint_name,
EndpointConfigName=classifier_epc_name,
)
print("Endpoint Arn: " + create_endpoint_response["EndpointArn"])
# wait for endpoint to reach a terminal state (InService) using describe endpoint
import time
describe_endpoint_response = client.describe_endpoint(EndpointName=endpoint_name)
while describe_endpoint_response["EndpointStatus"] == "Creating":
describe_endpoint_response = client.describe_endpoint(EndpointName=endpoint_name)
print(describe_endpoint_response["EndpointStatus"])
time.sleep(15)
describe_endpoint_response