Last active
January 25, 2021 20:42
-
-
Save sofianhamiti/3a9567e48f7f6d33391ff6b066f6e101 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import boto3 | |
| import logging | |
| from botocore.config import Config | |
| logger = logging.getLogger() | |
| logger.setLevel(logging.INFO) | |
| config = Config(retries = {'max_attempts': 10,'mode': 'standard'}) | |
| sagemaker = boto3.client('sagemaker', config=config) | |
| paginator = sagemaker.get_paginator('list_apps') | |
| def delete_app(domain_id, user_profile_name, app_type, app_name): | |
| logger.info(f'deleting {app_type}: {app_name} in Domain: {domain_id}') | |
| sagemaker.delete_app( | |
| DomainId=domain_id, | |
| UserProfileName=user_profile_name, | |
| AppType=app_type, | |
| AppName=app_name | |
| ) | |
| def lambda_handler(event, context): | |
| try: | |
| app_page_iterator = paginator.paginate(PaginationConfig={'PageSize': 50}) | |
| for app_page in app_page_iterator: | |
| for app in app_page['Apps']: | |
| if app['AppName'] != 'default' and app['Status'] != 'Deleted': | |
| delete_app(app['DomainId'], app['UserProfileName'], app['AppType'], app['AppName']) | |
| except Exception as e: | |
| logger.error(e) | |
| return 'Studio apps deleted' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment