{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## å‚考|今回作æˆã—ãŸãƒ¢ãƒ‹ã‚¿ãƒªãƒ³ã‚°ã‚¹ã‚±ã‚¸ãƒ¥ãƒ¼ãƒ«ã€ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆã€ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆæ§‹æˆã‚’削除ã™ã‚‹ã‚³ãƒ¼ãƒ‰\n", "与ãˆã‚‰ã‚ŒãŸæ–‡å—列ã«åå‰ã®ä¸€éƒ¨ãŒä¸€è‡´ã™ã‚‹ãƒªã‚½ãƒ¼ã‚¹ã‚’削除ã™ã‚‹ \n", "<span style=\"color: red; font-size: 140%;\">åå‰ã«ä¸€è‡´ã™ã‚‹ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆã€ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆæ§‹æˆã‚’自動ã§å‰Šé™¤ã™ã‚‹ã®ã§æ³¨æ„ã—ã¦å®Ÿè¡Œã—ã¦ãã ã•ã„ï¼ï¼</span>" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import boto3\n", "import time\n", "\n", "def delete_monitoring_schedule(target_substring):\n", " if not target_substring:\n", " print('Please specify deletion target sub-string')\n", " return\n", " \n", " sm = boto3.client('sagemaker')\n", " resp = sm.list_monitoring_schedules()\n", " schedule_names = [x['MonitoringScheduleName'] for x in resp['MonitoringScheduleSummaries']]\n", " target_schedule_names = [x for x in schedule_names if target_substring in x]\n", " print('Deletion target schedules:', target_schedule_names)\n", "\n", " for schedule_name in target_schedule_names:\n", " print(' Deleting...', schedule_name )\n", " sm.delete_monitoring_schedule(MonitoringScheduleName=schedule_name)\n", " \n", "def delete_endpoint(target_substring):\n", " if not target_substring:\n", " print('Please specify deletion target sub-string')\n", " return\n", " \n", " sm = boto3.client('sagemaker')\n", " resp = sm.list_endpoints()\n", " endpoint_names = [x['EndpointName'] for x in resp['Endpoints']]\n", " target_endpoint_names = [x for x in endpoint_names if target_substring in x]\n", " print('Deletion target endpoints:', target_endpoint_names)\n", "\n", " for endpoint_name in target_endpoint_names:\n", " print(' Deleting...', endpoint_name)\n", " sm.delete_endpoint(EndpointName=endpoint_name)\n", "\n", "def delete_endpoint_config(target_substring):\n", " if not target_substring:\n", " print('Please specify deletion target sub-string')\n", " return\n", " \n", " sm = boto3.client('sagemaker')\n", " resp = sm.list_endpoint_configs()\n", " endpoint_config_names = [x['EndpointConfigName'] for x in resp['EndpointConfigs']]\n", " target_config_names = [x for x in endpoint_config_names if target_substring in x]\n", " print('Deletion target endpoint configs', target_config_names)\n", "\n", " for endpoint_config_name in target_config_names:\n", " print(' Deleting...', endpoint_config_name)\n", " sm.delete_endpoint_config(EndpointConfigName=endpoint_config_name)\n", " \n", "def delete_endpoint_resources(target_substring):\n", " delete_monitoring_schedule(target_substring)\n", " time.sleep(3)\n", " delete_endpoint(target_substring)\n", " time.sleep(3)\n", " delete_endpoint_config(target_substring)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Deletion target schedules: []\n", "Deletion target endpoints: []\n", "Deletion target endpoint configs []\n" ] } ], "source": [ "# nyctaxi- ã‚’åå‰ã«å«ã‚€ãƒ¢ãƒ‹ã‚¿ãƒªãƒ³ã‚°ã‚¹ã‚±ã‚¸ãƒ¥ãƒ¼ãƒ«ã€æŽ¨è«–エンドãƒã‚¤ãƒ³ãƒˆã€ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆConfigã‚’é †ã«å‰Šé™¤ã™ã‚‹\n", "# スケジュールやエンドãƒã‚¤ãƒ³ãƒˆã®å‰Šé™¤ä¸ã«ä¾å˜ã™ã‚‹ã‚ªãƒ–ジェクトを削除ã—よã†ã¨ã™ã‚‹ã¨ã‚¨ãƒ©ãƒ¼ã«ãªã‚‹ã®ã§ã€ã—ã°ã‚‰ãå¾…ã£ã¦å†å®Ÿè¡Œã™ã‚‹\n", "\n", "# 下ã®ã‚³ãƒ¡ãƒ³ãƒˆã‚¢ã‚¦ãƒˆã‚’外ã—ã€å‰Šé™¤ã—ã¦ã‚‚よã„エンドãƒã‚¤ãƒ³ãƒˆåç‰ã‚’指定ã—ã¦å®Ÿè¡Œã—ã¦ãã ã•ã„\n", "# delete_endpoint_resources('nyctaxi-')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "instance_type": "ml.t3.medium", "kernelspec": { "display_name": "Python 3 (Data Science)", "language": "python", "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:ap-northeast-1:102112518831:image/datascience-1.0" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.10" } }, "nbformat": 4, "nbformat_minor": 4 }