From 1f7eec2f6c1264779b0b76f94f677a7634b3e9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Dsinanartun=E2=80=9D?= <26043673+sinanartun@users.noreply.github.com> Date: Fri, 27 Dec 2024 19:36:55 +0100 Subject: [PATCH] Add region availability check for SageMaker before deleting notebook instances; bump version to 0.5.49 --- main.py | 43 ++++++++++++++++++++++++++++++++++++------- setup.py | 2 +- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 0768531..d488aef 100644 --- a/main.py +++ b/main.py @@ -2072,16 +2072,45 @@ def delete_db_instances(self, region): def delete_all_notebook_instances(self, region_name): + available_regions = ['us-west-2', + 'af-south-1', + 'eu-north-1', + 'ap-east-1', + 'ap-southeast-2', + 'il-central-1', + 'sa-east-1', + 'eu-central-1', + 'ap-south-1', + 'eu-west-1', + 'ap-south-2', + 'us-west-1', + 'ap-northeast-3', + 'ap-southeast-3', + 'ap-northeast-1', + 'ap-southeast-1', + 'eu-west-3', + 'ca-central-1', + 'eu-west-2', + 'me-south-1', + 'me-central-1', + 'ap-northeast-2', + 'us-east-1', + 'us-east-2'] + + if region_name not in available_regions: + logger.info(f"Region {region_name} is not supported.") + return False - sagemaker_client = boto3.client('sagemaker', region_name=region_name) - s2 = boto3.Session(region_name=region_name) - available_services = s2.get_available_services() - if'sagemaker' not in available_services: - logger.info("SageMaker service is not available in the specified region.") + sagemaker_client = boto3.client('sagemaker', region_name=region_name) + if not hasattr(sagemaker_client, 'list_notebook_instances'): + # Call the method if it exists + + print(f"Method do not exists {region_name} and was called successfully.") return False - - + else: + print(f"Method exists {region_name} and was called successfully.") + # Get list of notebook instances response = sagemaker_client.list_notebook_instances() diff --git a/setup.py b/setup.py index 729e10a..24af201 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='aws-delete-all', - version='0.5.48', + version='0.5.49', author='Sinan Artun', author_email='sinanartun@gmail.com', description='A script that concurrently deletes common AWS resources like S3 buckets, RDS instances, and EC2 instances across all AWS regions.',