How to delete Feature Group from SageMaker Feature Store, by name

1.4k views Asked by At

The way to delete a feature group using the SageMaker Python SDK is as follows:

my_feature_group.delete()

But this only deletes the feature group you are currently working on. How can one delete feature groups from prior sessions? I tried deleting them out of the S3 bucket directly, but they still appear in the Feature Store UI.

It would be great if feature groups could be deleted through the UI. But if not, is there a way to delete a feature group using it's full name; the one that was created using:

my-feature-group-" + strftime("%d-%H-%M-%S", gmtime())
2

There are 2 answers

2
Jose Rondon On

You can loop over list_feature_groups as follows:

def extract_feature_groups(feature_groups):
    list_feature_groups = []
    list_feature_groups.extend([x['FeatureGroupName'] for x in feature_groups['FeatureGroupSummaries']])
    next_token = '' if not ('NextToken' in feature_groups.keys()) else feature_groups['NextToken']
    while not (next_token==''):
        page_feature_groups = boto_client.list_feature_groups(NextToken=next_token)
        list_feature_groups.extend([x['FeatureGroupName'] for x in page_feature_groups['FeatureGroupSummaries']])
        next_token = '' if not ('NextToken' in page_feature_groups.keys()) else page_feature_groups['NextToken']
    return list_feature_groups

region_name = <your_region_name>
boto_client = boto3.client('sagemaker', region_name=region_name)
boto_session = boto3.session.Session(region_name=region_name)
fs_sagemaker_session = sagemaker.Session(boto_session=boto_session)
feature_groups = boto_client.list_feature_groups()
list_features_groups = extract_feature_groups(feature_groups)

for fg in list_features_groups:
            <make sure to include appropriate name filter and/or confirmation requests>
            feature_group = FeatureGroup(name = feature, sagemaker_session = fs_sagemaker_session)
            feature_group.delete()

Feature groups take time to complete deletion; you might want to add a function for checking deletion has concluded successfully.

0
Anoop On

You can create a FeatureGroup object and call delete or via cli or SageMakerFeatureStoreRuntime client

source: aws