{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Cleanup\n", "---\n", "This will cleanup all the resources created in notebook 01 through 03.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import boto3\n", "import sagemaker\n", "from IPython.display import JSON\n", "region = boto3.session.Session().region_name\n", "comprehend=boto3.client('comprehend', region_name=region)\n", "data_bucket = sagemaker.Session().default_bucket()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Deleteing the model endpoint and Comprehend training jobs in your account.\n", "\n", "Run below code to delete Amazon Comprehend endpoints, custom classifier, and entity recognizer." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%store -r ER_ENDPOINT_ARN\n", "%store -r ENDPOINT_ARN\n", "%store -r entity_recognizer_arn\n", "%store -r document_classifier_arn\n", "print(f'Entity Recognizer Endpoint: {ER_ENDPOINT_ARN}')\n", "print(f'Entity Recognizer: {entity_recognizer_arn}')\n", "print(f'Custom Classifier Endpoint: {ENDPOINT_ARN}')\n", "print(f'Custom Classifier: {document_classifier_arn}')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Delete the custom classifier real-time endpoint" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ep_del_response = {}\n", "if ENDPOINT_ARN:\n", " ep_del_response = comprehend.delete_endpoint(\n", " EndpointArn=ENDPOINT_ARN\n", " )\n", "\n", "JSON(ep_del_response)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Delete the custom entity recognizer real-time endpoint" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "er_ep_del_response = {}\n", "if ER_ENDPOINT_ARN:\n", " er_ep_del_response = comprehend.delete_endpoint(\n", " EndpointArn=ER_ENDPOINT_ARN\n", " )\n", "\n", "JSON(ep_del_response)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Wait for Endpoints to delete" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Delete the custom classifier" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# List all classifiers in account\n", "dc_del_response = {}\n", "if document_classifier_arn:\n", " dc_del_response = comprehend.delete_document_classifier(\n", " DocumentClassifierArn=document_classifier_arn\n", " )\n", "\n", "JSON(dc_del_response)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Delete the custom entity recognizer" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# List all classifiers in account\n", "er_del_response = {}\n", "if entity_recognizer_arn:\n", " er_del_response = comprehend.delete_entity_recognizer(\n", " EntityRecognizerArn=entity_recognizer_arn\n", " )\n", "\n", "JSON(er_del_response)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Delete all the files that have been stored in the S3 bucket" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "os.system(f\"aws s3 rm s3://{data_bucket}/idp --recursive\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "# Delete A2I Human Review Workflow\n", "\n", "Follow the step-by-step instructions provided [here](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-delete-flow-definition.html) to delete the A2I Human Review Workflow. Once the human review workflow is deleted, delete the contents of the A2I bucket.\n", "\n", "**NOTE: replace the A2I bucket name `idp-a2i-xxxxxxxx` appropriately below before executing the code cell. To find out the bucket name, navigate to the Amazon S3 console and look for a bucket name starting with `idp-a2i-`.**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a2i_bucket=\"idp-a2i-xxxxxxxx\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "os.system(f\"aws s3 rm s3://{a2i_bucket} --recursive\")" ] }, { "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:us-east-2:429704687514: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 }