From 4651c240c4eb741ac88908979e64347921c30e1c Mon Sep 17 00:00:00 2001 From: prajwal Date: Sun, 19 May 2024 18:08:59 +0530 Subject: [PATCH] list only active endpoints --- src/main.py | 2 +- src/sagemaker/resources.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.py b/src/main.py index 93e39f6..5cefd97 100644 --- a/src/main.py +++ b/src/main.py @@ -40,7 +40,7 @@ def main(args, loglevel): instance_thread.start() while True: - active_endpoints = list_sagemaker_endpoints() + active_endpoints = list_sagemaker_endpoints(onlyActive=True) questions = [ inquirer.List( 'action', diff --git a/src/sagemaker/resources.py b/src/sagemaker/resources.py index 85ab434..43672ce 100644 --- a/src/sagemaker/resources.py +++ b/src/sagemaker/resources.py @@ -8,7 +8,7 @@ from typing import List, Tuple, Dict, Optional -def list_sagemaker_endpoints(filter_str: str = None) -> List[str]: +def list_sagemaker_endpoints(filter_str: str = None, onlyActive: bool = False) -> List[str]: sagemaker_client = boto3.client('sagemaker') endpoints = sagemaker_client.list_endpoints()['Endpoints'] @@ -17,12 +17,14 @@ def list_sagemaker_endpoints(filter_str: str = None) -> List[str]: x['EndpointName'], endpoints)) for endpoint in endpoints: + # The 'InService' state indicates that the endpoint is ready to accept requests. + if onlyActive and ('EndpointStatus' not in endpoint or endpoint['EndpointStatus'] != 'InService'): + continue endpoint_config = sagemaker_client.describe_endpoint_config( EndpointConfigName=endpoint['EndpointName'])['ProductionVariants'][0] endpoint['InstanceType'] = endpoint_config['InstanceType'] return endpoints - def get_sagemaker_endpoint(endpoint_name: str) -> Optional[Dict[str, Optional[Dict]]]: endpoints = list_sagemaker_endpoints(endpoint_name) if not endpoints: