{ "cells": [ { "cell_type": "markdown", "id": "e4055eba", "metadata": {}, "source": [ "# Clean-up Resource" ] }, { "cell_type": "markdown", "id": "1ffb7844", "metadata": {}, "source": [ "# 1. lab_01_training" ] }, { "cell_type": "markdown", "id": "b9ac7765", "metadata": {}, "source": [ "### SageMaker Experiments" ] }, { "cell_type": "code", "execution_count": 7, "id": "4569773b", "metadata": {}, "outputs": [], "source": [ "import time\n", "\n", "from smexperiments.experiment import Experiment\n", "from smexperiments.trial import Trial\n", "from smexperiments.trial_component import TrialComponent" ] }, { "cell_type": "code", "execution_count": 8, "id": "47050075", "metadata": {}, "outputs": [], "source": [ "experiment_name='xgboost-poc-1' #<== 생성한 experiment_name을 넣어야 합니다." ] }, { "cell_type": "code", "execution_count": 9, "id": "7fca004f", "metadata": {}, "outputs": [], "source": [ "def cleanup_sme_sdk(experiment):\n", " for trial_summary in experiment.list_trials():\n", " trial = Trial.load(trial_name=trial_summary.trial_name)\n", " for trial_component_summary in trial.list_trial_components():\n", " tc = TrialComponent.load(\n", " trial_component_name=trial_component_summary.trial_component_name)\n", " trial.remove_trial_component(tc)\n", " try:\n", " # comment out to keep trial components\n", " tc.delete()\n", " except:\n", " # tc is associated with another trial\n", " continue\n", " # to prevent throttling\n", " time.sleep(.5)\n", " trial.delete()\n", " experiment_name = experiment.experiment_name\n", " experiment.delete()\n", " print(f\"\\nExperiment {experiment_name} deleted\")" ] }, { "cell_type": "code", "execution_count": 10, "id": "a07773c6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Experiment xgboost-poc-1 deleted\n" ] } ], "source": [ "experiment_to_cleanup = Experiment.load(\n", " # Use experiment name not display name\n", " experiment_name=experiment_name)\n", "\n", "cleanup_sme_sdk(experiment_to_cleanup)" ] }, { "cell_type": "markdown", "id": "7869fb2a", "metadata": {}, "source": [ "## S3 버킷 삭제" ] }, { "cell_type": "code", "execution_count": 11, "id": "9e26e91d", "metadata": {}, "outputs": [], "source": [ "import sagemaker" ] }, { "cell_type": "code", "execution_count": 12, "id": "ae0fb2e2", "metadata": {}, "outputs": [], "source": [ "sagemaker_session = sagemaker.session.Session()" ] }, { "cell_type": "code", "execution_count": 13, "id": "fa0843ae", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'sagemaker-us-east-1-051065130547'" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bucket = sagemaker_session.default_bucket()\n", "bucket" ] }, { "cell_type": "code", "execution_count": 14, "id": "957a2ff6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "delete: s3://sagemaker-us-east-1-051065130547/xgboost\n" ] } ], "source": [ "!aws s3 rm s3://$bucket/xgboost" ] }, { "cell_type": "markdown", "id": "cbce9d04", "metadata": {}, "source": [ "# 2. lab_03_pipeline " ] }, { "cell_type": "markdown", "id": "00d8fb89", "metadata": {}, "source": [ "## 2.1. 파이프라인 삭제\n" ] }, { "cell_type": "markdown", "id": "359b6c61", "metadata": {}, "source": [ "### 파이프라인 이름 검색\n", "- \"sagemaker-webinar\" 이름으로 시작되는 파이프라인 정보 검색" ] }, { "cell_type": "code", "execution_count": null, "id": "9a5852ef", "metadata": {}, "outputs": [], "source": [ "import boto3\n", "\n", "client = boto3.client('sagemaker')\n", "\n", "response = client.list_pipelines(\n", " PipelineNamePrefix='sagemaker-webinar',\n", " SortBy='Name',\n", " SortOrder='Descending',\n", " MaxResults=1\n", ")\n", "\n", "response" ] }, { "cell_type": "markdown", "id": "e42313f1", "metadata": {}, "source": [ "### 'sagemaker-webinar-pipeline-base' 파이프라인 삭제" ] }, { "cell_type": "code", "execution_count": null, "id": "47e53097", "metadata": {}, "outputs": [], "source": [ "deleted_pipeline = 'sagemaker-webinar-pipeline-base'\n", "response = client.delete_pipeline(\n", " PipelineName=deleted_pipeline,\n", ")\n", "response" ] }, { "cell_type": "markdown", "id": "485bbe0c", "metadata": {}, "source": [ "### 'sagemaker-webinar-pipeline-base' 파이프라인 관련된 버킷 내용 삭제" ] }, { "cell_type": "code", "execution_count": null, "id": "298a480f", "metadata": {}, "outputs": [], "source": [ "! aws s3 rm s3://{bucket}/{deleted_pipeline} --recursive" ] }, { "cell_type": "markdown", "id": "065fb92c", "metadata": {}, "source": [ "### 버킷의 첫번째 폴더 리스트\n", "- 아래와 같은 모둔 폴더를 확인하신 후에 필요한 폴더는 삭제 하세요." ] }, { "cell_type": "code", "execution_count": 6, "id": "305d96c6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " PRE Fraud-Advance-Eval-955a33142036ab10f5b2dc96b96cd633/\n", " PRE Fraud-Advance-Evaluation-955a33142036ab10f5b2dc96b96cd633/\n", " PRE Fraud-Advance-Preprocess-9eb3e47661f2f1f3db35bb21017985f2/\n", " PRE Fraud-Basic-Preprocess-476f3bbbf986da0944ce9ca52d7c54b6/\n", " PRE Fraud-Basic-Process-476f3bbbf986da0944ce9ca52d7c54b6/\n", " PRE Fraud-Basic-Process-f65211cab06c0afa0f94d059ed66c9e6/\n", " PRE FraudScratchProcess-f65211cab06c0afa0f94d059ed66c9e6/\n", " PRE fraud2train/\n", " PRE sagemaker-pipeline-step-by-step/\n", " PRE sagemaker-webinar-pipeline-advanced/\n", " PRE sagemaker-xgboost-2022-03-21-12-18-21-232/\n", " PRE sagemaker-xgboost-2022-03-21-12-18-21-493/\n", " PRE sagemaker-xgboost-2022-03-21-12-26-39-683/\n", " PRE sagemaker-xgboost-2022-03-21-12-26-41-259/\n", " PRE sagemaker-xgboost-2022-03-21-12-41-40-939/\n", " PRE sagemaker-xgboost-2022-03-21-12-41-41-179/\n", " PRE sagemaker-xgboost-2022-03-21-12-41-41-479/\n", " PRE sagemaker-xgboost-2022-03-21-12-41-41-670/\n", " PRE xgboost-poc-1-m5-2xl-1-xgboost-d-0322-07191647933553/\n", " PRE xgboost/\n" ] } ], "source": [ "! aws s3 ls {bucket}" ] }, { "cell_type": "markdown", "id": "3e4aeeb7", "metadata": {}, "source": [ "## 2.2 앤드포인트 삭제 확인\n", "- 아래와 같이 세이지 메이커 콘솔에 가서, 혹시 앤드포인트가 있나를 확인 하세요. 존재하면 아래 그림과 같이 삭제 하시기 바랍니다." ] }, { "cell_type": "markdown", "id": "b2ab0186", "metadata": {}, "source": [ "![delete_endpoint.png](img/delete_endpoint.png)" ] }, { "cell_type": "markdown", "id": "6356d4b0", "metadata": {}, "source": [ "# 4. SageMaker Classic Notebook 삭제" ] }, { "cell_type": "markdown", "id": "cd49a47f", "metadata": {}, "source": [ "## 4.1. CloudFormation 콘솔로 이동\n", "- 아래와 같이 \"서비스 창\" 에 \"Cloudf\" 입력\n", "- 그리고 CloudFormation 서비스 메뉴가 나오면 클릭" ] }, { "cell_type": "markdown", "id": "96d0510a", "metadata": {}, "source": [ "![cf_console.png](img/cf_console.png)" ] }, { "cell_type": "markdown", "id": "12cf07de", "metadata": {}, "source": [ "## 4.2. 스텍 선택 후에 삭제\n", "- 아래와 같이 처음 설치했던 스텍 (예: sagemaker-notebook) 선택\n", "- 그리고 삭제 버튼 클릭" ] }, { "cell_type": "markdown", "id": "396b5a72", "metadata": {}, "source": [ "![remove_stack.png](img/remove_stack.png)" ] }, { "cell_type": "markdown", "id": "dc0e8837", "metadata": {}, "source": [ "## 4.3. 세이지 메이커 콘솔로 이동\n", "- 왼쪽 메뉴의 \"노트북 >> 노트북 인스턴스\" 클릭\n", "- 그리고 (2) 번의 \"Stopping\" 확인" ] }, { "cell_type": "markdown", "id": "98ac62a5", "metadata": {}, "source": [ "![go_sm_console.png](img/go_sm_console.png)" ] }, { "cell_type": "markdown", "id": "a442e998", "metadata": {}, "source": [ "## 4.4. 노트북 삭제 확인\n", "- 아래와 같이 해당 노트북이 지워지면, 해당 노트북 인스턴스가 보이지 않습니다. " ] }, { "cell_type": "markdown", "id": "b530c9ea", "metadata": {}, "source": [ "![sure_notebook.png](img/sure_notebook.png)" ] }, { "cell_type": "markdown", "id": "0cad6fd9", "metadata": {}, "source": [ "#### 오늘 하루 동안 고생 많이 하셨습니다. 많은 배우셨기를 기원 합니다. 고맙습니다." ] }, { "cell_type": "code", "execution_count": null, "id": "a00524d4", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "conda_python3", "language": "python", "name": "conda_python3" }, "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.6.13" } }, "nbformat": 4, "nbformat_minor": 5 }