2

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())
Cybernetic
  • 12,628
  • 16
  • 93
  • 132

2 Answers2

4

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

source: aws

Anoop
  • 102
  • 3
1

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.

Jose Rondon
  • 370
  • 2
  • 6
  • 13
  • any suggestion on how to do that? I tried checking if the feature group name still shows up in `list_feature_groups()` but it seems to disappear here before being fully deleted. – oW_ May 20 '22 at 16:40
  • @oW_ try describe_feature_group() (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.describe_feature_group) There you have in the response `FeatureGroupStatus` which would show "Deleting" when it is in the process to be deleted. You must use it with try/except sentences, so to handle properly. – Jose Rondon May 23 '22 at 09:17