<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>
StarcoderdataJupyterStructuredCleanDedup