Skip to content

Commit

Permalink
Add region availability check for SageMaker before deleting notebook …
Browse files Browse the repository at this point in the history
…instances; bump version to 0.5.49
  • Loading branch information
sinanartun committed Dec 27, 2024
1 parent 2aa9c7f commit 1f7eec2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
43 changes: 36 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='aws-delete-all',
version='0.5.48',
version='0.5.49',
author='Sinan Artun',
author_email='[email protected]',
description='A script that concurrently deletes common AWS resources like S3 buckets, RDS instances, and EC2 instances across all AWS regions.',
Expand Down

0 comments on commit 1f7eec2

Please sign in to comment.