<jupyter_start><jupyter_text>Amazon Personalize Workshop Part 3 - Cleanup the resources> After building your model you may want to delete your campaign, solutions, and datasets.- toc: true- badges: true- comments: true- categories: [amazonpersonalize, movie]- image:<jupyter_code># Imports
import boto3
import json
import numpy as np
import pandas as pd
import time
# Configure the SDK to Personalize:
personalize = boto3.client('personalize')
personalize_runtime = boto3.client('personalize-runtime')<jupyter_output><empty_output><jupyter_text>Defining the Things to CleanupUsing the store command we will retrieve all the values needed to cleanup our work.<jupyter_code>%store -r
# Delete the campaign:
personalize.delete_campaign(campaignArn=campaign_arn)
time.sleep(60)
# Delete the solution
personalize.delete_solution(solutionArn=solution_arn)
time.sleep(60)
# Delete the event tracker
personalize.delete_event_tracker(eventTrackerArn=event_tracker_arn)
time.sleep(60)
# Delete the interaction dataset
personalize.delete_dataset(datasetArn=dataset_arn)
time.sleep(60)
# Delete the event dataset
event_interactions_dataset_arn = dataset_arn
event_interactions_dataset_arn = event_interactions_dataset_arn.replace("INTERACTIONS", "EVENT_INTERACTIONS")
personalize.delete_dataset(datasetArn=event_interactions_dataset_arn)
time.sleep(60)
# Delete the schema
personalize.delete_schema(schemaArn=schema_arn)<jupyter_output><empty_output><jupyter_text>Empty Your S3 BucketNext empty your S3 bucket, you uploaded a movie file to it in the first notebook.<jupyter_code>boto3.Session().resource('s3').Bucket(bucket).Object(filename).delete()<jupyter_output><empty_output><jupyter_text>IAM Policy CleanupThe 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.<jupyter_code># IAM policies should also be removed
iam = boto3.client("iam")
iam.detach_role_policy(PolicyArn="arn:aws:iam::aws:policy/AmazonS3FullAccess", RoleName=role_name)
iam.detach_role_policy(PolicyArn="arn:aws:iam::aws:policy/service-role/AmazonPersonalizeFullAccess",RoleName=role_name)

iam.delete_role(RoleName=role_name)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08485931219294328, 'fraction_numerical': 0.008932559178204555, 'mean_word_length': 8.655172413793103, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '144430', 'license': 'MIT-0', 'n_tokens_mistral': 704, 'n_tokens_neox': 671, 'n_words': 178, 'path': 'getting_started/notebooks/2021-06-20-amazon-personalize-workshop-part-3.ipynb', 'repo_name': 'sparsh-data-001/reco-amazon-personalize', 'size': '2239'}