This notebook is provided to help you clean up any resources you have created by running through the example. You should also go to the CloudFormation console and delete the stack that you created.
from sagemaker import get_execution_role
import sagemaker
import boto3
import json
import sys

role = get_execution_role()
sm = boto3.Session().client(service_name='sagemaker')

Delete feature groups

%store -r
try:
    sm.delete_feature_group(FeatureGroupName=fg_name) 
    print('deleted '+fg_name)
except:
    pass
deleted heidelberg-mlops-fg
sm.list_feature_groups()
{'FeatureGroupSummaries': [{'FeatureGroupName': 'transaction-feature-group-15-05-22-59',
   'FeatureGroupArn': 'arn:aws:sagemaker:us-east-1:082830052325:feature-group/transaction-feature-group-15-05-22-59',
   'CreationTime': datetime.datetime(2020, 12, 15, 5, 23, 10, 113000, tzinfo=tzlocal()),
   'FeatureGroupStatus': 'Created',
   'OfflineStoreStatus': {'Status': 'Active'}},
  {'FeatureGroupName': 'ml-ops-2',
   'FeatureGroupArn': 'arn:aws:sagemaker:us-east-1:082830052325:feature-group/ml-ops-2',
   'CreationTime': datetime.datetime(2020, 12, 19, 6, 49, 19, 335000, tzinfo=tzlocal()),
   'FeatureGroupStatus': 'Created'},
  {'FeatureGroupName': 'ml-ops-1',
   'FeatureGroupArn': 'arn:aws:sagemaker:us-east-1:082830052325:feature-group/ml-ops-1',
   'CreationTime': datetime.datetime(2020, 12, 18, 7, 7, 15, 38000, tzinfo=tzlocal()),
   'FeatureGroupStatus': 'Created'},
  {'FeatureGroupName': 'identity-feature-group-15-05-22-59',
   'FeatureGroupArn': 'arn:aws:sagemaker:us-east-1:082830052325:feature-group/identity-feature-group-15-05-22-59',
   'CreationTime': datetime.datetime(2020, 12, 15, 5, 23, 7, 513000, tzinfo=tzlocal()),
   'FeatureGroupStatus': 'Created',
   'OfflineStoreStatus': {'Status': 'Active'}},
  {'FeatureGroupName': 'heidelberg-mlops-fg-test1',
   'FeatureGroupArn': 'arn:aws:sagemaker:us-east-1:082830052325:feature-group/heidelberg-mlops-fg-test1',
   'CreationTime': datetime.datetime(2020, 12, 30, 6, 41, 36, 615000, tzinfo=tzlocal()),
   'FeatureGroupStatus': 'Created'},
  {'FeatureGroupName': 'heidelberg-mlops-fg',
   'FeatureGroupArn': 'arn:aws:sagemaker:us-east-1:082830052325:feature-group/heidelberg-mlops-fg',
   'CreationTime': datetime.datetime(2021, 1, 5, 17, 49, 57, 235000, tzinfo=tzlocal()),
   'FeatureGroupStatus': 'Deleting',
   'OfflineStoreStatus': {'Status': 'Active'}},
  {'FeatureGroupName': 'heidelberg-fg-test2',
   'FeatureGroupArn': 'arn:aws:sagemaker:us-east-1:082830052325:feature-group/heidelberg-fg-test2',
   'CreationTime': datetime.datetime(2020, 12, 29, 9, 18, 2, 298000, tzinfo=tzlocal()),
   'FeatureGroupStatus': 'Created'},
  {'FeatureGroupName': 'heidelberg-fg-test',
   'FeatureGroupArn': 'arn:aws:sagemaker:us-east-1:082830052325:feature-group/heidelberg-fg-test',
   'CreationTime': datetime.datetime(2020, 12, 29, 8, 57, 48, 782000, tzinfo=tzlocal()),
   'FeatureGroupStatus': 'Created'},
  {'FeatureGroupName': 'demo-feature-group-2',
   'FeatureGroupArn': 'arn:aws:sagemaker:us-east-1:082830052325:feature-group/demo-feature-group-2',
   'CreationTime': datetime.datetime(2020, 12, 29, 4, 56, 13, 540000, tzinfo=tzlocal()),
   'FeatureGroupStatus': 'Created'},
  {'FeatureGroupName': 'demo-feature-group',
   'FeatureGroupArn': 'arn:aws:sagemaker:us-east-1:082830052325:feature-group/demo-feature-group',
   'CreationTime': datetime.datetime(2020, 12, 28, 6, 17, 12, 601000, tzinfo=tzlocal()),
   'FeatureGroupStatus': 'Created'}],
 'NextToken': 'cIws2QhTXUIa8bi8XYNGwqMND6lavWZ6uZcw9539cUOD10M54amsd7l7yk4ucGW0YBYA+27e3qBpT0v/9eeXaZHI0OynQP0MGWxQIEMxEgPAFTlgHQc4BCc2dClH5/oyLuP4y3HU1Uc+hOt7PjxjfX85eToHqu60szYdvyQww5AIcHO98C+c6aArPfKWA9At4vupqSH+tFFjELqIHIc4VppahmW2c4V08+Ih3icbhVTdkJqtxW32ij3UaIEmXVj2ewAC85aPdqMp6PHmaua2EO6cdfewvaM4/TDk1kXkJblj4Un+QvQlTqL5q5HpO1LGfU5HIKxZNaoe3bC/szFmTTELP1QnIafcIPijnSvnTmHuytOw/Nk8pEhlABQ8yNBEQvy6Rh0cwxasIJdvzO/THM/8QwFTHXtTwp24StY+widOwWlh0SqGCdR/8UxYEFQEUZ3t4fi08RtBh8aQeWYadbd8IwJv6rLl4yUhEZM4KKxVoHI/B5Ge/Sg4Lf3Pq9wK3nS3QowfTbCLYj8CLs6tfvTfAQ==',
 'ResponseMetadata': {'RequestId': 'ae9c6043-c054-4b4d-93e1-4bd299a61749',
  'HTTPStatusCode': 200,
  'HTTPHeaders': {'x-amzn-requestid': 'ae9c6043-c054-4b4d-93e1-4bd299a61749',
   'content-type': 'application/x-amz-json-1.1',
   'content-length': '2747',
   'date': 'Tue, 05 Jan 2021 18:13:27 GMT'},
  'RetryAttempts': 0}}

Stop the KDA SQL App

%store -r
import boto3
kda_client = boto3.client('kinesisanalytics')

try:
    kda_client.stop_application(ApplicationName=APPLICATION_NAME)
except:
    pass

print('Stopped the KDA SQL app')
Stopped the KDA SQL app

Delete the KDA SQL App

import time
%store -r 

try:
    ready = False
    while not ready:
        app_desc = kda_client.describe_application(ApplicationName=APPLICATION_NAME)['ApplicationDetail']
        if app_desc['ApplicationStatus'] == 'READY':
            ready = True
        else:
            print('Waiting for KDA SQL app to be ready for deletion...')
            time.sleep(15)
    create_timestamp = app_desc['CreateTimestamp']
    response = kda_client.delete_application(ApplicationName=APPLICATION_NAME,
                                  CreateTimestamp=create_timestamp)
    print('Deleted KDA SQL app')
except:
    print('FAILED to delete KDA sql app')
Waiting for KDA SQL app to be ready for deletion...
Deleted KDA SQL app

Remove the trigger from Lambda

import boto3

%store -r 

lambda_client = boto3.client('lambda')
paginator = lambda_client.get_paginator('list_event_source_mappings')
mapping_iterator = paginator.paginate(FunctionName=lambda_to_model_arn)

for m in mapping_iterator:
    if len(m['EventSourceMappings']) > 0:
        uuid = m['EventSourceMappings'][0]['UUID']
        print(f'Deleting mapping: {uuid}...')
        lambda_client.delete_event_source_mapping(UUID=uuid)
Deleting mapping: 9974f2db-2d9a-4081-9e31-7cbb227ca548...

Delete the Kinesis data stream

%store -r
kinesis_client = boto3.client('kinesis')
try:
    kinesis_client.delete_stream(StreamName=STREAM_NAME)
except:
    pass
print('deleted Kinesis stream')
deleted Kinesis stream

Delete the SageMaker endpoint

%store -r
#endpoint_name="sagemaker-xgboost-2020-12-23-06-52-57-726"
try:
    sm.delete_endpoint(EndpointName=endpoint_name)
except:
    print("yes")
    pass