{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Module 6. 리소스 삭제\n", "\n", "모델을 구축한 후 캠페인(campaign), 솔루션(solution) 및 데이터셋(dataset)을 삭제할 수 있습니다. 다음 셀은 이 핸즈온에서 생성한 모든 리소스를 삭제합니다.\n", "\n", "## 라이브러리 임포트 및 AWS 연결 \n", "\n", "아래 코드 셀은 필요한 모든 라이브러리를 가져온 다음 Amazon Personalize에 연결합니다." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Imports\n", "import boto3\n", "import json\n", "import numpy as np\n", "import pandas as pd\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Configure the SDK to Personalize:\n", "personalize = boto3.client('personalize')\n", "personalize_runtime = boto3.client('personalize-runtime')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 정리할 항목 정의\n", "\n", "`store` 매직 커맨드를 사용하여 작업 정리에 필요한 모든 값들을 검색합니다." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%store -r" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Delete the campaign:\n", "personalize.delete_campaign(campaignArn=hrnn_campaign_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "personalize.delete_campaign(campaignArn=hrnn_coldstart_campaign_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "personalize.delete_campaign(campaignArn=sims_campaign_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "personalize.delete_campaign(campaignArn=ranking_campaign_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Delete the solution\n", "personalize.delete_solution(solutionArn=hrnn_solution_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "personalize.delete_solution(solutionArn=hrnn_coldstart_solution_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "personalize.delete_solution(solutionArn=sims_solution_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "personalize.delete_solution(solutionArn=ranking_solution_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Delete the event tracker\n", "personalize.delete_event_tracker(eventTrackerArn=event_tracker_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Delete the interaction dataset\n", "personalize.delete_dataset(datasetArn=interaction_dataset_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Delete the item dataset\n", "personalize.delete_dataset(datasetArn=item_dataset_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Delete the event dataset\n", "\n", "event_interactions_dataset_arn = dataset_group_arn\n", "event_interactions_dataset_arn = event_interactions_dataset_arn.replace(\":dataset-group\", \":dataset\")\n", "event_interactions_dataset_arn =event_interactions_dataset_arn +'/EVENT_INTERACTIONS'\n", "personalize.delete_dataset(datasetArn=event_interactions_dataset_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Delete the schema\n", "personalize.delete_schema(schemaArn=interaction_schema_arn)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "personalize.delete_schema(schemaArn=item_schema_arn)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Delete the DatasetGroup\n", "personalize.delete_dataset_group(\n", " datasetGroupArn=dataset_group_arn\n", ")\n", "time.sleep(60)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## S3 버킷 삭제\n", "\n", "첫 번째 노트북에서 업로드한 S3 버킷을 삭제합니다." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#!aws s3 rm s3://bucket/ --recursive \n", "#!aws s3 rb s3://bucket --force \n", "#boto3.Session().resource('s3').Bucket(bucket).Object(filename).delete()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## IAM 정책 삭제\n", "\n", "본 notebook의 마지막 단계는 역할에 연결된 정책들을 제거한 다음 역할을 삭제하는 것입니다. 아래 셀을 그대로 실행하시면 됩니다." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# IAM policies should also be removed\n", "iam = boto3.client(\"iam\")\n", "iam.detach_role_policy(PolicyArn=\"arn:aws:iam::aws:policy/AmazonS3FullAccess\", RoleName=role_name)\n", "iam.detach_role_policy(PolicyArn=\"arn:aws:iam::aws:policy/service-role/AmazonPersonalizeFullAccess\",RoleName=role_name)\n", "\n", "iam.delete_role(RoleName=role_name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 마지막 단계\n", "\n", "모든 리소스를 정리한 후, 이제 이 창을 닫고 시작한 github 페이지로 돌아갈 수 있습니다. \n", "처음에 생성했던 CloudFormation까지 삭제하면 본 핸즈온랩에서 생성했던 리소스를 모두 삭제할 수 있습니다. (CloudFormation 사용시)\n", "\n", "수고하셨습니다." ] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 4 }