{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 리소스 제거\n", "❗ 이 노트북은 데이터 변환 및 피쳐 프로젝트에서 생성된 모든 리소스를 제거합니다. 다음 코드 셀은 다음을 수행합니다.\n", "- Studio 환경에서 프로비저닝한 프로젝트를 영구적으로 삭제\n", "- 피쳐 그룹 또는 그룹을 영구적으로 삭제\n", "- 프로젝트 프로비저닝된 S3 버킷을 영구적으로 삭제\n", "- 프로젝트 관련 접두사 아래에 있는 S3 버킷의 객체를 영구적으로 삭제\n", "- 관련 스택 제거" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
💡 소스를 삭제합니다. 삭제할 리소스의 이름을 다시 확인하십시오! \n", "
" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import sagemaker\n", "import boto3\n", "import time\n", "import json\n", "import os" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# load environment variables from %store\n", "%store -r " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Stored variables and their in-db values:\n", "abalone_dataset_file_name -> 'abalone.csv'\n", "abalone_dataset_local_url -> '../dataset/abalone.csv'\n", "data_bucket -> 'sagemaker-us-east-1-627616086164'\n", "domain_id -> 'd-qlke3qpg5lek'\n", "dw_flow_file_url -> 's3://sagemaker-us-east-1-627616086164/feature-sto\n", "dw_output_name -> 'c8880ed5-b8a0-4375-899b-1c4d86828152.default'\n", "execution_role -> 'arn:aws:iam::627616086164:role/mod-6297809195fe48\n", "feature_group_name -> 'FG-abalone-07-12-33-46-45860802'\n", "s3_data_prefix -> 'sagemaker-us-east-1-627616086164/feature-store-in\n", "s3_flow_prefix -> 'sagemaker-us-east-1-627616086164/feature-store-in\n", "s3_fs_query_output_prefix -> 'sagemaker-us-east-1-627616086164/feature-store-in\n", "s3_input_data_prefix -> 'sagemaker-us-east-1-627616086164/feature-store-in\n", "s3_to_fs_pipeline_name -> 's3-fs-ingest-pipeline-p-i6gxlpp9tkqj'\n" ] } ], "source": [ "%store" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "try:\n", " s3_data_prefix\n", " s3_flow_prefix\n", " s3_input_data_prefix\n", " s3_fs_query_output_prefix\n", "except NameError:\n", " print(\"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\")\n", " print(\"[ERROR] YOU HAVE TO RUN 00-setup.ipynb and 01-feature-store-ingest-pipeline notebooks\")\n", " print(\"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "sm = boto3.client(\"sagemaker\")\n", "s3 = boto3.resource('s3')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. 프로젝트 삭제\n", "- 셀 실행 후에 \"Y\" 를 입력 해주세요." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "These projects have been created by domain d-qlke3qpg5lek: [\n", " {\n", " \"ProjectName\": \"s3-fs-ingest-07-12-38-24\",\n", " \"ProjectId\": \"p-i6gxlpp9tkqj\"\n", " }\n", "]\n" ] } ], "source": [ "# Get all projects created by the current domain\n", "projects = [\n", " {\"ProjectName\":p[\"ProjectName\"], \"ProjectId\":p[\"ProjectId\"]} for p in sm.list_projects(MaxResults=100, SortBy=\"CreationTime\")[\"ProjectSummaryList\"] \n", " if sm.describe_project(ProjectName=p[\"ProjectName\"])[\"CreatedBy\"][\"DomainId\"] == domain_id and p[\"ProjectStatus\"] == \"CreateCompleted\"\n", "]\n", "\n", "print(f\"These projects have been created by domain {domain_id}: {json.dumps(projects, indent=2)}\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Are you sure you want to delete this project: s3-fs-ingest-07-12-38-24? (y/n)\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ " y\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "***************************************\n", "The following projects will be deleted:\n", "[\n", " {\n", " \"ProjectName\": \"s3-fs-ingest-07-12-38-24\",\n", " \"ProjectId\": \"p-i6gxlpp9tkqj\"\n", " }\n", "]\n", "***************************************\n" ] } ], "source": [ "# Select projects to be deleted\n", "projects_to_delete = []\n", "\n", "for p in projects:\n", " print(f\"Are you sure you want to delete this project: {p['ProjectName']}? (y/n)\")\n", " choice = input()\n", " if choice == 'y':\n", " projects_to_delete.append(p)\n", " \n", "print(f\"***************************************\")\n", "print(f\"The following projects will be deleted:\\n{json.dumps(projects_to_delete, indent=2)}\")\n", "print(f\"***************************************\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
💡 프로젝트를 삭제합니다. 모든 프로젝트 CodeCommit 코드 리포지토리 및 CI/CD CodePipeline 파이프라인이 삭제됩니다! \n", "
" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Deleting project s3-fs-ingest-07-12-38-24:{'ResponseMetadata': {'RequestId': '5bfedecc-e0a6-4a36-b0e8-424573285a4d', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '5bfedecc-e0a6-4a36-b0e8-424573285a4d', 'content-type': 'application/x-amz-json-1.1', 'content-length': '0', 'date': 'Mon, 07 Feb 2022 13:33:09 GMT'}, 'RetryAttempts': 0}}\n" ] } ], "source": [ "for p in projects_to_delete:\n", " try:\n", " print(f\"Deleting project {p['ProjectName']}:{sm.delete_project(ProjectName=p['ProjectName'])}\")\n", " except Exception:\n", " pass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2. 피쳐 스토어의 피쳐 그룹 삭제\n", "- 셀 실행 후에 \"Y\" 를 입력 해주세요." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "feature_groups = sm.list_feature_groups(\n", " FeatureGroupStatusEquals=\"Created\", \n", " SortOrder=\"Descending\", \n", " SortBy=\"CreationTime\"\n", ")[\"FeatureGroupSummaries\"]" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'FeatureGroupName': 'FG-abalone-07-12-33-46-45860802',\n", " 'FeatureGroupArn': 'arn:aws:sagemaker:us-east-1:627616086164:feature-group/fg-abalone-07-12-33-46-45860802',\n", " 'CreationTime': datetime.datetime(2022, 2, 7, 12, 36, 41, 150000, tzinfo=tzlocal()),\n", " 'FeatureGroupStatus': 'Created'}]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "feature_groups" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Are you sure you want to delete this feature group: FG-abalone-07-12-33-46-45860802? (y/n)\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ " y\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "********************************************\n", "The following feature groups will be deleted:\n", "[\n", " \"FG-abalone-07-12-33-46-45860802\"\n", "]\n", "********************************************\n" ] } ], "source": [ "# Select feature groups to be deleted\n", "feature_groups_to_delete = []\n", "\n", "for fg in feature_groups:\n", " print(f\"Are you sure you want to delete this feature group: {fg['FeatureGroupName']}? (y/n)\")\n", " choice = input()\n", " if choice == 'y':\n", " feature_groups_to_delete.append(fg[\"FeatureGroupName\"])\n", " \n", "print(f\"********************************************\")\n", "print(f\"The following feature groups will be deleted:\\n{json.dumps(feature_groups_to_delete, indent=2)}\")\n", "print(f\"********************************************\")\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "def delete_offline_store(feature_group_name: str):\n", " try:\n", " offline_store_config = sm.describe_feature_group(FeatureGroupName=feature_group_name)['OfflineStoreConfig']\n", "\n", " except Exception:\n", " print(f'Feature group: {feature_group_name} does NOT have an offline store!')\n", " return\n", " \n", " offline_store_s3_uri = offline_store_config['S3StorageConfig']['ResolvedOutputS3Uri']\n", " print(f\"all feature store objects under {offline_store_s3_uri} will be deleted!\")\n", " print(\"Are you sure you want to these objects ? (y/n)\")\n", " \n", " choice = input()\n", " if choice == 'y':\n", " !aws s3 rm {offline_store_s3_uri} --recursive" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
💡 다음 코드 셀은 선택한 기능 그룹을 삭제합니다!\n", "
" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Deleting the feature group: FG-abalone-07-12-33-46-45860802\n", "all feature store objects under s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data will be deleted!\n", "Are you sure you want to these objects ? (y/n)\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ " y\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00001-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00000-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00014-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00003-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00015-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00016-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00008-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00018-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00017-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00005-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00004-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00010-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00019-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00020-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00022-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00002-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00021-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00023-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00024-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00013-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00025-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00026-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00007-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00027-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00028-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00030-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00029-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00031-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00011-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00006-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00012-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n", "delete: s3://sagemaker-us-east-1-627616086164/627616086164/sagemaker/us-east-1/offline-store/FG-abalone-07-12-33-46-45860802-1644237401/data/year=2022/month=02/day=07/hour=12/part-00009-b9c48a42-7652-473a-b2bc-e25556e2f8d5.c000.parquet\n" ] } ], "source": [ "for fg in feature_groups_to_delete:\n", " print(f\"Deleting the feature group: {fg}\")\n", " delete_offline_store(fg)\n", " sm.delete_feature_group(FeatureGroupName=fg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 3. sm-project-sc-portfolio 스택 제거" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "SC_PORTFOLIO_STACK_NAME='sm-project-sc-portfolio'" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SM_SC_FS_INGESTION_POLICY_ARN : arn:aws:iam::627616086164:policy/sm-project-sc-portfolio-AmazonSageMakerServiceCatalogFSIngestionProductPolicy-1ELCY7G3Q44HC\n", "\n", "SM_EXECUTION_ROLE_POLICY_ARN : arn:aws:iam::627616086164:policy/sm-project-sc-portfolio-AmazonSageMakerExecutionRolePolicy-X02MZ0KBMA39\n", "\n", "SM_EXECUTION_ROLE_NAME : mod-6297809195fe4845-SageMakerExecutionRole-1BEMVGZB3KC6H\n", "Policies are detached\n", "Portfolio stack is deleted\n" ] } ], "source": [ "%%sh -s \"{SC_PORTFOLIO_STACK_NAME}\" \n", "\n", "sc_portfolio_stack_name=$1\n", "export SM_SC_FS_INGESTION_POLICY_ARN=$(aws cloudformation describe-stacks \\\n", " --stack-name $sc_portfolio_stack_name \\\n", " --output text \\\n", " --query 'Stacks[0].Outputs[?OutputKey==`FSIngestionProductPolicyArn`].OutputValue')\n", "\n", "echo 'SM_SC_FS_INGESTION_POLICY_ARN' : $SM_SC_FS_INGESTION_POLICY_ARN\n", " \n", "export SM_EXECUTION_ROLE_POLICY_ARN=$(aws cloudformation describe-stacks \\\n", " --stack-name $sc_portfolio_stack_name \\\n", " --output text \\\n", " --query 'Stacks[0].Outputs[?OutputKey==`AmazonSageMakerExecutionRolePolicyArn`].OutputValue')\n", "\n", "echo ''\n", "echo 'SM_EXECUTION_ROLE_POLICY_ARN' : $SM_EXECUTION_ROLE_POLICY_ARN \n", " \n", "export SM_EXECUTION_ROLE_NAME=$(aws cloudformation describe-stacks \\\n", " --stack-name $sc_portfolio_stack_name \\\n", " --output text \\\n", " --query 'Stacks[0].Outputs[?OutputKey==`AmazonSageMakerExecutionRoleName`].OutputValue')\n", "\n", "echo ''\n", "echo 'SM_EXECUTION_ROLE_NAME' : $SM_EXECUTION_ROLE_NAME \n", "\n", "echo \"Policies are detached\" \n", "aws iam detach-role-policy \\\n", " --role-name AmazonSageMakerServiceCatalogProductsLaunchRole \\\n", " --policy-arn $SM_SC_FS_INGESTION_POLICY_ARN\n", "\n", "aws iam detach-role-policy \\\n", " --role-name $SM_EXECUTION_ROLE_NAME \\\n", " --policy-arn $SM_EXECUTION_ROLE_POLICY_ARN\n", "\n", "echo \"Portfolio stack is deleted\" \n", "aws cloudformation delete-stack --stack-name $sc_portfolio_stack_name\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 4. 제공된 amazon-sagemaker-reusable-components-package-cfn 스택 제거\n" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "%%sh\n", "\n", "aws iam attach-role-policy \\\n", " --role-name AmazonSageMakerServiceCatalogProductsLaunchRole \\\n", " --policy-arn arn:aws:iam::aws:policy/IAMFullAccess\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "%%sh\n", "aws cloudformation delete-stack --stack-name amazon-sagemaker-reusable-components-package-cfn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "클라우드 포메이션 콘솔로 이동해서 확인 합니다.\n", "\n", "![cfn-template-rm.png](img/cfn-template-rm.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 5. 프로젝트 프로비저닝된 S3 버킷 삭제" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
💡 \n", "다음 코드 셀은 프로젝트에서 생성된 모든 S3 버킷을 삭제합니다!\n", "
" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "*****************************************************\n", "The following S3 buckets will be removed permanently!\n", "*****************************************************\n", "sagemaker-cp-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj\n", "sagemaker-ct-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj\n" ] } ], "source": [ "print(f\"*****************************************************\")\n", "print(f\"The following S3 buckets will be removed permanently!\")\n", "print(f\"*****************************************************\")\n", "for p in projects_to_delete:\n", " print(f\"sagemaker-cp-{p['ProjectName']}-{p['ProjectId']}\")\n", " print(f\"sagemaker-ct-{p['ProjectName']}-{p['ProjectId']}\")" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "delete: s3://sagemaker-cp-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj/sagemaker-s3-fs-inge/DataLoadPi/qphLWiO\n", "remove_bucket: sagemaker-cp-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj\n", "delete: s3://sagemaker-ct-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj/AWSLogs/627616086164/CloudTrail/us-east-1/2022/02/07/627616086164_CloudTrail_us-east-1_20220207T1245Z_5Ov1XNUzKaRGav77.json.gz\n", "delete: s3://sagemaker-ct-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj/AWSLogs/627616086164/CloudTrail/\n", "delete: s3://sagemaker-ct-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj/AWSLogs/627616086164/CloudTrail/us-east-1/2022/02/07/627616086164_CloudTrail_us-east-1_20220207T1245Z_2hSXuetVS2c8R4Dt.json.gz\n", "delete: s3://sagemaker-ct-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj/AWSLogs/627616086164/CloudTrail/us-east-1/2022/02/07/627616086164_CloudTrail_us-east-1_20220207T1250Z_TTDBa49DsPDtt22C.json.gz\n", "delete: s3://sagemaker-ct-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj/AWSLogs/627616086164/CloudTrail/us-east-1/2022/02/07/627616086164_CloudTrail_us-east-1_20220207T1245Z_7fopNExZ1I84TGF6.json.gz\n", "delete: s3://sagemaker-ct-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj/AWSLogs/627616086164/CloudTrail/us-east-1/2022/02/07/627616086164_CloudTrail_us-east-1_20220207T1250Z_bP0IS9DgZ93K5Kji.json.gz\n", "delete: s3://sagemaker-ct-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj/AWSLogs/627616086164/CloudTrail/us-east-1/2022/02/07/627616086164_CloudTrail_us-east-1_20220207T1330Z_PAV7l8jN0mEfAaYD.json.gz\n", "remove_bucket: sagemaker-ct-s3-fs-ingest-07-12-38-24-p-i6gxlpp9tkqj\n" ] } ], "source": [ "for p in projects_to_delete:\n", " !aws s3 rb s3://sagemaker-cp-{p['ProjectName']}-{p['ProjectId']} --force \n", " !aws s3 rb s3://sagemaker-ct-{p['ProjectName']}-{p['ProjectId']} --force" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 6. S3 데이터 버킷에서 프로젝트 관련 객체 제거" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
💡 \n", "다음 코드 셀은 지정된 S3 접두사 아래의 모든 객체를 삭제합니다.!\n", "
" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "prefixes_to_delete = [\n", " s3_data_prefix,\n", " s3_flow_prefix,\n", " s3_input_data_prefix,\n", " s3_fs_query_output_prefix\n", "]" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "************************************************************************\n", "All objects under the following S3 prefixes will be removed permanently!\n", "************************************************************************\n", "sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/dataset/\n", "sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/dw-flow/\n", "sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/landing-zone/\n", "sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/fs_query_results/\n" ] } ], "source": [ "print(f\"************************************************************************\")\n", "print(f\"All objects under the following S3 prefixes will be removed permanently!\")\n", "print(f\"************************************************************************\")\n", "for p in prefixes_to_delete:\n", " print(p)" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "delete: s3://sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/dataset/abalone.csv\n", "delete: s3://sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/dataset/abalone.data\n", "delete: s3://sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/dataset/abalone.names\n", "delete: s3://sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/dw-flow/dw2-flow-07-12-33-46-45860802.flow\n", "delete: s3://sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/landing-zone/abalone-07-12-40-51.csv\n", "delete: s3://sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/fs_query_results/ef31e53c-e168-4bf0-ab3c-17bb1fb34a90.csv.metadata\n", "delete: s3://sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/fs_query_results/121745e2-00bf-4bfa-bbbe-512d5bf4d453.csv.metadata\n", "delete: s3://sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/fs_query_results/121745e2-00bf-4bfa-bbbe-512d5bf4d453.csv\n", "delete: s3://sagemaker-us-east-1-627616086164/feature-store-ingestion-pipeline/fs_query_results/ef31e53c-e168-4bf0-ab3c-17bb1fb34a90.csv\n" ] } ], "source": [ "for p in prefixes_to_delete:\n", " !aws s3 rm s3://{p} --recursive" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 7. 노트북 리소스 제거" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "

Shutting down your kernel for this notebook to release resources.

\n", "\n", " \n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "\n", "

Shutting down your kernel for this notebook to release resources.

\n", "\n", " \n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 8. 노트북 및 실행 중인 노트북 인스턴스를 종료" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
💡 아래에서 노트북을 셧다운 해주세요. \n", "그리고 RUNNING INSTANCE 가 필요 없으면 역시 꺼주세요. \n", "\n", "\n", "
\n", "\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 9. Next\n", "계속 리소스 제거를 위해서 여기로 이동해주세요. [README-Action](../README-Action.md)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (Data Science)", "language": "python", "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199: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 }