Created
May 9, 2024 00:55
-
-
Save garystafford/7b0dc1970b8aeaa9737a06d7cef49099 to your computer and use it in GitHub Desktop.
Delete all Amazon SageMaker Models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Gary A. Stafford | |
# Purpose: Delete all SageMaker Models | |
# Date: 2024-05-08 | |
# License: MIT License | |
# Based on https://gist.github.com/Nxtra/49cde5999de20023e2607433046ca6cf | |
import boto3 | |
client = boto3.client("sagemaker") | |
def main(): | |
model_names = [] | |
for key in paginate(client.list_models): | |
model_names.append(key["ModelName"]) | |
delete_multiple_models(model_names) | |
def delete_multiple_models(model_names): | |
for model_name in model_names: | |
print("Deleting model: {}".format(model_name)) | |
client.delete_model(ModelName=model_name) | |
def paginate(method, **kwargs): | |
client = method.__self__ | |
paginator = client.get_paginator(method.__name__) | |
for page in paginator.paginate(**kwargs).result_key_iters(): | |
for result in page: | |
yield result | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment