{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Cleanup\n", "\n", "After building your model you may want to delete your campaign, solutions, and datasets. The following cells will ensure that you have successfully cleaned up all of the resources you created in this lab.\n", "\n", "## Imports and Connectins to AWS\n", "\n", "The following lines import all the necessary libraries and then connect you to Amazon Personalize.\n" ] }, { "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": [ "## Defining the Things to Cleanup\n", "\n", "Using the store command we will retrieve all the values needed to cleanup our work." ] }, { "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=campaign_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Delete the solution\n", "personalize.delete_solution(solutionArn=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=dataset_arn)\n", "time.sleep(60)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Delete the event dataset\n", "event_interactions_dataset_arn = dataset_arn\n", "event_interactions_dataset_arn = event_interactions_dataset_arn.replace(\"INTERACTIONS\", \"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=schema_arn)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Empty Your S3 Bucket\n", "\n", "Next empty your S3 bucket, you uploaded a movie file to it in the first notebook.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "boto3.Session().resource('s3').Bucket(bucket).Object(filename).delete()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## IAM Policy Cleanup\n", "\n", "The very last step in the notebooks is to remove the policies that were attached to a role and then to delete it. No changes should need to be made here, just execute the cell." ] }, { "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": [ "## Last Step\n", "\n", "After cleaning up all of the resources you can now close this window and go back to the github page you stareted on. At the bottom of the Readme file are steps to delete the CloudFormation stack you created earlier. Once that is done you are 100% done with the lab.\n", "\n", "Congratulations!" ] }, { "cell_type": "code", "execution_count": null, "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.5" } }, "nbformat": 4, "nbformat_minor": 4 }