{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "df50504b-9d55-47f9-bdd0-9a14338d9ed7", "metadata": {}, "source": [ "# Delete SageMaker resources\n", "\n", "Delete the endpoint, model." ] }, { "cell_type": "code", "execution_count": null, "id": "973d7e56-8f9a-400d-bd0b-d743ca2234a5", "metadata": {}, "outputs": [], "source": [ "# Imports\n", "import boto3\n", "import time\n", "import sagemaker" ] }, { "cell_type": "code", "execution_count": null, "id": "df7c6235-f01b-4543-84a9-e95974c7ed48", "metadata": {}, "outputs": [], "source": [ "sagemaker_session = sagemaker.session.Session()\n", "role = sagemaker.get_execution_role()\n", "bucket = sagemaker.session.Session().default_bucket()\n", "\n", "sagemaker_client = boto3.client('sagemaker')\n" ] }, { "cell_type": "code", "execution_count": null, "id": "33f0273a-0396-4967-9714-58d5c487b940", "metadata": {}, "outputs": [], "source": [ "%store -r" ] }, { "attachments": {}, "cell_type": "markdown", "id": "7a147353-1ae8-4252-905e-1dc3ec127f4e", "metadata": {}, "source": [ "# 1. Delete Endpoint" ] }, { "cell_type": "code", "execution_count": null, "id": "62a79a27-bcdc-456d-b5c0-3d1d589db68a", "metadata": {}, "outputs": [], "source": [ "# Delete the endpoint\n", "sagemaker_client.delete_endpoint(\n", " EndpointName=endpoint_name\n", ")\n", "print(f\"Endpoint '{endpoint_name}' deleted.\")\n", "time.sleep(10)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "08d9d7b4-48bd-433f-9433-556cd1f0f01f", "metadata": {}, "source": [ "# 2. Delete Endpoint configuration" ] }, { "cell_type": "code", "execution_count": null, "id": "e2fc1ac7-2c51-4e07-9544-477d23d7ce99", "metadata": {}, "outputs": [], "source": [ "# Delete the endpoint config\n", "sagemaker_client.delete_endpoint_config(\n", " EndpointConfigName=endpoint_config_name\n", ")\n", "print(f\"Endpoint config '{endpoint_config_name}' deleted.\")\n", "\n", "time.sleep(10)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "c3c42105-cc88-4007-8bb9-9c2b45d0af8d", "metadata": {}, "source": [ "# 3. Delete Model" ] }, { "cell_type": "code", "execution_count": null, "id": "fed3b5b0-60b7-4d7d-a726-81e51445e7f7", "metadata": {}, "outputs": [], "source": [ "# Delete the model\n", "sagemaker_client.delete_model(\n", " ModelName=model_name\n", ")\n", "print(f\"Model '{model_name}' deleted.\")" ] }, { "attachments": {}, "cell_type": "markdown", "id": "f4191ce8-9e49-4504-8820-fc8a1ed17266", "metadata": {}, "source": [ "# 4. Delete S3 files(model, code)" ] }, { "cell_type": "code", "execution_count": null, "id": "859a0bd3-e3ed-4736-bc99-d88e9692126b", "metadata": {}, "outputs": [], "source": [ "s3_path = \"s3://{}/{}/\".format(bucket, 'ncf')\n", "\n", "! aws s3 rm {s3_path} --recursive" ] }, { "attachments": {}, "cell_type": "markdown", "id": "267b724c-caad-480b-9a7c-e85436cd35c9", "metadata": { "tags": [] }, "source": [ "### Delete local stored variable\n" ] }, { "cell_type": "code", "execution_count": null, "id": "c09d2261-2a45-498b-88ac-faeed40f274b", "metadata": {}, "outputs": [], "source": [ "%store -Z" ] }, { "cell_type": "code", "execution_count": null, "id": "21678f54-1178-44b4-83d5-3af7b6eff7d9", "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.10.6" } }, "nbformat": 4, "nbformat_minor": 5 }